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