upload tizen1.0 source
[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
29 #include "JSWidget.h"
30 #include "JSPreferences.h"
31 #include "JSTest.h"
32
33 #include "IFrameSupport.h"
34 #include "AddEventListenerSupport.h"
35
36 #define OBJECT_WIDGET "widget"
37 #define OBJECT_PREFERENCES "preferences"
38 #define OBJECT_TEST "__test"
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 };
55
56 class_definition_options_t AddEventListenerOptions =
57 {
58     JS_FUNCTION,
59     CREATE_INSTANCE,
60     ALWAYS_NOTICE,
61     OVERLAYED_BEFORE_ORIGINAL,
62     IFrameSupport::RegisterAddEventListener,
63     NULL
64 };
65
66 };
67
68 void on_widget_start_callback(int widgetId)
69 {
70     LogDebug("[W3C\\widget] on_widget_start_callback (" << widgetId << ")");
71
72     Try
73     {
74         WrtAccessSingleton::Instance().initialize(widgetId);
75     }
76     Catch (Commons::Exception)
77     {
78         LogError("Wrt wrapper registration failed");
79         return;
80     }
81 }
82
83 void on_widget_stop_callback(int widgetId)
84 {
85     LogDebug("[W3C\\widget] on_widget_stop_callback (" << widgetId << ")");
86     Try
87     {
88         WrtAccessSingleton::Instance().deinitialize(widgetId);
89     }
90     Catch (Commons::Exception)
91     {
92         LogError("Wrt wrapper registration failed");
93         return;
94     }
95
96 }
97
98 PLUGIN_ON_WIDGET_START(on_widget_start_callback)
99 PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
100
101 PLUGIN_CLASS_MAP_BEGIN
102 PLUGIN_CLASS_MAP_ADD_CLASS (WRT_JS_EXTENSION_OBJECT_GLOBAL,
103         OBJECT_WIDGET,
104         WrtPlugins::W3C::JSWidget::getClassRef(),
105         &Options::WidgetOptions)
106 //PLUGIN_CLASS_MAP_ADD_CLASS(OBJECT_WIDGET,
107 //                           OBJECT_PREFERENCES,
108 //                           WrtPlugins::W3C::JSPreferences::getClassRef(),
109 //                           NULL)
110 //Function::AddEventListener
111 PLUGIN_CLASS_MAP_ADD_CLASS (WRT_JS_EXTENSION_OBJECT_GLOBAL,
112                             "addEventListener",
113                             (const void*)
114                                 AddEventListenerSupport::AddEventListener,
115                             &Options::AddEventListenerOptions)
116 #ifdef W3C_TEST
117 PLUGIN_CLASS_MAP_ADD_CLASS(OBJECT_WIDGET,
118                            OBJECT_TEST,
119                            WrtPlugins::W3C::JSTest::getClassRef(),
120                            NULL)
121 #endif // W3C_TEST
122 PLUGIN_CLASS_MAP_END
123
124 #undef OBJECT_WIDGET
125 #undef OBJECT_PREFERENCES