Source code formating unification
[platform/framework/web/wrt.git] / src / view / webkit / bundles / plugin_module_support.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    plugin_module_support.cpp
18  * @author  Lukasz Wrzosek (l.wrzosek@samsung.com)
19  * @author  Yunchan Cho (yunchan.cho@samsung.com)
20  * @brief   Plugin module support for Webkit2 - implementation.
21  */
22 #include "plugin_module_support.h"
23 #include "messages_names.h"
24
25 #include <sstream>
26 #include <EWebKit2.h>
27 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
28 #include <js_overlay_types.h>
29
30 namespace PluginModuleSupport {
31 void init(Ewk_Context* ewkContext, const std::string& tizenId)
32 {
33     const char* name = BundleMessages::INIT;
34     const char* msg = tizenId.c_str();
35
36     ewk_context_message_post_to_injected_bundle(ewkContext, name, msg);
37 }
38
39 void start(Ewk_Context* ewkContext,
40            const DPL::String& tizenId,
41            double scale,
42            const char *encodedBundle,
43            const char *theme,
44            bool encrypted)
45 {
46     std::stringstream ssMsg;
47
48     std::string id = DPL::ToUTF8String(tizenId);
49     ssMsg << id << " ";
50
51     ssMsg << "_" << scale << " ";
52
53     if (encodedBundle) {
54         ssMsg << "_" << encodedBundle << " ";
55     } else {
56         ssMsg << "null" << " ";
57     }
58
59     if (theme) {
60         ssMsg << "_" << theme << " ";
61     } else {
62         ssMsg << "null" << " ";
63     }
64
65     ssMsg << encrypted;
66
67     std::string msgString = ssMsg.str();
68
69     const char* msg = msgString.c_str();
70     const char* name = BundleMessages::START;
71
72     ewk_context_message_post_to_injected_bundle(ewkContext, name, msg);
73 }
74
75 void shutdown(Ewk_Context* ewkContext)
76 {
77     const char* name = BundleMessages::SHUTDOWN;
78     ewk_context_message_post_to_injected_bundle(ewkContext, name, name);
79 }
80
81 void setCustomProperties(
82     Ewk_Context* ewkContext,
83     double* scale,
84     const char* encodedBundle,
85     const char* theme)
86 {
87     std::stringstream ssMsg;
88
89     if (scale) {
90         ssMsg << "_" << *scale << " ";
91     } else {
92         ssMsg << "null" << " ";
93     }
94
95     if (encodedBundle) {
96         ssMsg << "_" << encodedBundle << " ";
97     } else {
98         ssMsg << "null" << " ";
99     }
100
101     if (theme) {
102         ssMsg << "_" << theme;
103     } else {
104         ssMsg << "null";
105     }
106
107     std::string msgString = ssMsg.str();
108
109     const char* msg = msgString.c_str();
110     const char* name = BundleMessages::SET_CUSTOM_PROPERTIES;
111
112     ewk_context_message_post_to_injected_bundle(ewkContext, name, msg);
113 }
114
115 void dispatchJavaScriptEvent(
116     Ewk_Context* ewkContext,
117     WrtPlugins::W3C::CustomEventType eventType,
118     void *data)
119 {
120     using namespace WrtPlugins::W3C;
121     std::stringstream str;
122     str << eventType;
123
124     // if needed, arguments for event should be set here
125     if (eventType == SoftKeyboardChangeCustomEvent) {
126         if (data) {
127             SoftKeyboardChangeArgs* args =
128                 static_cast<SoftKeyboardChangeArgs *>(data);
129             str << " " << args->state;
130             str << " " << args->width;
131             str << " " << args->height;
132         }
133     }
134
135     std::string msgString = str.str();
136     const char* msg = msgString.c_str();
137     const char* name = BundleMessages::DISPATCH_JAVASCRIPT_EVENT;
138
139     ewk_context_message_post_to_injected_bundle(ewkContext, name, msg);
140 }
141
142 void suspend(Ewk_Context* ewkContext)
143 {
144     const char* name = BundleMessages::SUSPEND;
145     ewk_context_message_post_to_injected_bundle(ewkContext, name, name);
146 }
147
148 void resume(Ewk_Context* ewkContext)
149 {
150     const char* name = BundleMessages::RESUME;
151     ewk_context_message_post_to_injected_bundle(ewkContext, name, name);
152 }
153 } //namespace PluginModuleSupport