Update wrt-plugins-common_0.3.53
[framework/web/wrt-plugins-common.git] / src / standards / W3C / Widget / plugin_initializer.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  *
18  * @file       plugin_initializer.cpp
19  * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
20  * @version    0.1
21  * @brief
22  */
23
24 #include <dpl/log/log.h>
25
26 #include <Commons/plugin_initializer_def.h>
27 #include <Commons/WrtAccess/WrtAccess.h>
28 #include <js-overlay/js_overlay_addEventListener.h>
29 #include <js-overlay/js_iframe_support.h>
30
31 #include "JSWidget.h"
32 #include "JSPreferences.h"
33
34 #include "plugin_config.h"
35
36 #define OBJECT_WIDGET "widget"
37 #define INTERFACE_WIDGET_NAME "Widget"
38 #define OBJECT_PREFERENCES "preferences"
39
40 using namespace WrtPlugins::W3C;
41 using namespace WrtDeviceApis;
42 using namespace WrtDeviceApis::Commons;
43
44 namespace Options{
45
46 class_definition_options_t WidgetOptions =
47 {
48     JS_CLASS,
49     CREATE_INSTANCE,
50     ALWAYS_NOTICE,
51     USE_OVERLAYED, //ignored
52     IFrameSupport::RegisterWidget,
53     NULL,
54     NULL
55 };
56
57 class_definition_options_t WidgetInterfaceOptions =
58 {
59     JS_INTERFACE,
60     CREATE_INSTANCE,
61     ALWAYS_NOTICE,
62     USE_OVERLAYED, //ignored
63     JSWidget::acquireGlobalContext,
64     NULL,
65     NULL
66 };
67
68 };
69
70 void on_widget_init_callback(feature_mapping_interface_t *mapping)
71 {
72     LogDebug("[W3C\\widget] on_widget_init_callback");
73
74     WrtPlugins::W3C::WidgetDeclarations::getMappingInterface(mapping);
75 }
76
77 void on_widget_start_callback(int widgetId)
78 {
79     LogDebug("[W3C\\widget] on_widget_start_callback (" << widgetId << ")");
80
81     Try
82     {
83         WrtAccessSingleton::Instance().initialize(widgetId);
84     }
85     Catch (Commons::Exception)
86     {
87         LogError("Wrt wrapper registration failed");
88         return;
89     }
90 }
91
92 void on_widget_stop_callback(int widgetId)
93 {
94     LogDebug("[W3C\\widget] on_widget_stop_callback (" << widgetId << ")");
95     Try
96     {
97         WrtAccessSingleton::Instance().deinitialize(widgetId);
98     }
99     Catch (Commons::Exception)
100     {
101         LogError("Wrt wrapper registration failed");
102         return;
103     }
104
105 }
106
107 PLUGIN_ON_WIDGET_START(on_widget_start_callback)
108 PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
109 PLUGIN_ON_WIDGET_INIT(on_widget_init_callback)
110
111 PLUGIN_CLASS_MAP_BEGIN
112 PLUGIN_CLASS_MAP_ADD_INTERFACE(
113         WRT_JS_EXTENSION_OBJECT_GLOBAL,
114         INTERFACE_WIDGET_NAME,
115         (js_class_template_getter)WrtPlugins::W3C::JSWidget::getClassRef,
116         reinterpret_cast<js_class_constructor_cb_t>(WrtPlugins::W3C::JSWidget::callAsConstructor),
117         &Options::WidgetInterfaceOptions)
118 PLUGIN_CLASS_MAP_ADD_INTERFACE_PRODUCT(
119         WRT_JS_EXTENSION_OBJECT_GLOBAL,
120         OBJECT_WIDGET,
121         INTERFACE_WIDGET_NAME,
122         &Options::WidgetOptions)
123
124 PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_GLOBAL,
125         OBJECT_WIDGET,
126         (js_class_template_getter)WrtPlugins::W3C::JSWidget::getClassRef,
127         &Options::WidgetOptions)
128 PLUGIN_CLASS_MAP_END
129
130 #undef OBJECT_WIDGET
131 #undef OBJECT_PREFERENCES