Update wrt-plugins-common_0.3.53
[platform/framework/web/wrt-plugins-common.git] / src / js-overlay / js_function_manager.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file    js_function_manager.cpp
18  * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
19  * @author  Yunchan Cho (yunchan.cho@samgsung.com)
20  * @version
21  * @brief
22  */
23
24 #include <dpl/singleton_safe_impl.h>
25 #include <js_function_manager.h>
26 #include <js_iframe_support.h>
27 #include <js_overlay_functions.h>
28 #include <js_overlay_addEventListener.h>
29 #include <wrt_plugin_export.h>
30
31 using namespace WrtPlugins::W3C;
32
33 IMPLEMENT_SAFE_SINGLETON(JsFunctionManager)
34
35 namespace {
36 const char* JSPRINT_NAME = "jsPrint";
37 const char* JSGLOBAL_OBJECT = "GLOBAL_OBJECT";
38 const char* JSHOOK_NAME = "jsHook";
39 const char* ADD_EVENT_LISTENER_NAME = "addEventListener";
40 }
41
42 namespace JavaScriptFunctions
43 {
44 //options
45     class_definition_options_t jsHookfunctionsOptions =
46     {
47         JS_FUNCTION,
48         CREATE_INSTANCE,
49         NONE_NOTICE,
50         USE_OVERLAYED, //ignored
51         NULL,
52         NULL,
53         reinterpret_cast<js_function_impl>(JSCFunctions::JavaScriptHookProc)
54     };
55
56     class_definition_options_t jsPrintfunctionsOptions =
57     {
58         JS_FUNCTION,
59         CREATE_INSTANCE,
60         NONE_NOTICE,
61         USE_OVERLAYED, //ignored
62         NULL,
63         NULL,
64         reinterpret_cast<js_function_impl>(JSCFunctions::JavaScriptPrintProc)
65     };
66
67     class_definition_options_t addEventListenerOptions =
68     {
69         JS_FUNCTION,
70         CREATE_INSTANCE,
71         ALWAYS_NOTICE,
72         OVERLAYED_BEFORE_ORIGINAL,
73         IFrameSupport::RegisterAddEventListener,
74         NULL,
75         reinterpret_cast<js_function_impl>(AddEventListenerSupport::AddEventListener)
76     };
77
78     js_entity_definition_t jsPrint =
79     {
80         JSGLOBAL_OBJECT,
81         JSPRINT_NAME,
82         "",
83         NULL,
84         NULL,
85         &jsPrintfunctionsOptions
86     };
87
88     js_entity_definition_t jsHook =
89     {
90         JSGLOBAL_OBJECT,
91         JSHOOK_NAME,
92         "",
93         NULL,
94         NULL,
95         &jsHookfunctionsOptions
96     };
97
98     js_entity_definition_t addEventListener =
99     {
100         JSGLOBAL_OBJECT,
101         ADD_EVENT_LISTENER_NAME,
102         "",
103         NULL,
104         NULL,
105         &addEventListenerOptions
106     };
107     const js_entity_definition_ptr_t jsPrintPtr = &jsPrint;
108     const js_entity_definition_ptr_t jsHookPtr = &jsHook;
109     const js_entity_definition_ptr_t addEventListenerPtr = &addEventListener;
110 }
111
112
113 bool JsFunctionManager::initialize()
114 {
115     LogInfo("JSObjectDeclaration for js functions are intialized");
116     JSObjectDeclarationPtr jsPrintObj(
117         new JSObjectDeclaration(JavaScriptFunctions::jsPrintPtr));
118
119     JSObjectDeclarationPtr jsHookObj(
120         new JSObjectDeclaration(JavaScriptFunctions::jsHookPtr));
121
122     JSObjectDeclarationPtr addEventListenerObj(
123         new JSObjectDeclaration(JavaScriptFunctions::addEventListenerPtr));
124
125     m_functions.push_back(jsPrintObj);
126     m_functions.push_back(jsHookObj);
127     m_functions.push_back(addEventListenerObj);
128
129     return true;
130 }
131
132 JsFunctionManager::Functions JsFunctionManager::getFunctions()
133 {
134     LogInfo("get standard js fucntions");
135     static bool initialized = initialize();
136     (void) initialized;
137     return m_functions;
138 }