[Release] wrt-plugins-common_0.3.104
[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_overlay_functions.h>
27 #include <wrt_plugin_export.h>
28 #include <dpl/log/secure_log.h>
29
30 IMPLEMENT_SAFE_SINGLETON(JsFunctionManager)
31
32 namespace {
33 const char* JSPRINT_NAME = "jsPrint";
34 const char* JSGLOBAL_OBJECT = "GLOBAL_OBJECT";
35 const char* JSHOOK_NAME = "jsHook";
36 }
37
38 namespace JavaScriptFunctions {
39 //options
40 class_definition_options_t jsHookfunctionsOptions = {
41     JS_FUNCTION,
42     CREATE_INSTANCE,
43     NONE_NOTICE,
44     USE_OVERLAYED,     //ignored
45     NULL,
46     NULL,
47     reinterpret_cast<js_function_impl>(JSCFunctions::JavaScriptHookProc)
48 };
49
50 class_definition_options_t jsPrintfunctionsOptions = {
51     JS_FUNCTION,
52     CREATE_INSTANCE,
53     NONE_NOTICE,
54     USE_OVERLAYED,     //ignored
55     NULL,
56     NULL,
57     reinterpret_cast<js_function_impl>(JSCFunctions::JavaScriptPrintProc)
58 };
59
60 js_entity_definition_t jsPrint = {
61     JSGLOBAL_OBJECT,
62     JSPRINT_NAME,
63     "",
64     NULL,
65     NULL,
66     &jsPrintfunctionsOptions
67 };
68
69 js_entity_definition_t jsHook = {
70     JSGLOBAL_OBJECT,
71     JSHOOK_NAME,
72     "",
73     NULL,
74     NULL,
75     &jsHookfunctionsOptions
76 };
77
78 const js_entity_definition_ptr_t jsPrintPtr = &jsPrint;
79 const js_entity_definition_ptr_t jsHookPtr = &jsHook;
80 }
81
82 bool JsFunctionManager::initialize()
83 {
84     _D("JSObjectDeclaration for js functions are intialized");
85     JSObjectDeclarationPtr jsPrintObj(
86         new JSObjectDeclaration(JavaScriptFunctions::jsPrintPtr));
87
88     JSObjectDeclarationPtr jsHookObj(
89         new JSObjectDeclaration(JavaScriptFunctions::jsHookPtr));
90
91     m_functions.push_back(jsPrintObj);
92     m_functions.push_back(jsHookObj);
93
94     return true;
95 }
96
97 JsFunctionManager::Functions JsFunctionManager::getFunctions()
98 {
99     _D("get standard js fucntions");
100     static bool initialized = initialize();
101     (void) initialized;
102     return m_functions;
103 }