tizen 2.3.1 release
[framework/web/mobile/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 <EWebKit.h>
26 #include <EWebKit_internal.h>
27 #include <message_support.h>
28 #include <js_overlay_types.h>
29
30 namespace ViewLogicMessageSupport {
31 void init(Ewk_Context* ewkContext, const std::string& tizenId)
32 {
33     const char* name = Message::ToInjectedBundle::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 {
45     std::stringstream ssMsg;
46
47     std::string id = DPL::ToUTF8String(tizenId);
48     ssMsg << id << " ";
49
50     ssMsg << "_" << scale << " ";
51
52     if (encodedBundle) {
53         ssMsg << "_" << encodedBundle << " ";
54     } else {
55         ssMsg << "null" << " ";
56     }
57
58     if (theme) {
59         ssMsg << "_" << theme;
60     } else {
61         ssMsg << "null";
62     }
63
64     std::string msgString = ssMsg.str();
65
66     const char* msg = msgString.c_str();
67     const char* name = Message::ToInjectedBundle::START;
68
69     ewk_context_message_post_to_injected_bundle(ewkContext, name, msg);
70 }
71
72 void shutdown(Ewk_Context* ewkContext)
73 {
74     const char* name = Message::ToInjectedBundle::SHUTDOWN;
75     ewk_context_message_post_to_injected_bundle(ewkContext, name, name);
76 }
77
78 void setCustomProperties(
79     Ewk_Context* ewkContext,
80     double* scale,
81     const char* encodedBundle,
82     const char* theme)
83 {
84     std::stringstream ssMsg;
85
86     if (scale) {
87         ssMsg << "_" << *scale << " ";
88     } else {
89         ssMsg << "null" << " ";
90     }
91
92     if (encodedBundle) {
93         ssMsg << "_" << encodedBundle << " ";
94     } else {
95         ssMsg << "null" << " ";
96     }
97
98     if (theme) {
99         ssMsg << "_" << theme;
100     } else {
101         ssMsg << "null";
102     }
103
104     std::string msgString = ssMsg.str();
105
106     const char* msg = msgString.c_str();
107     const char* name = Message::ToInjectedBundle::SET_CUSTOM_PROPERTIES;
108
109     ewk_context_message_post_to_injected_bundle(ewkContext, name, msg);
110 }
111
112 void dispatchJavaScriptEvent(
113     Ewk_Context* ewkContext,
114     WrtPlugins::W3C::CustomEventType eventType,
115     void *data)
116 {
117     using namespace WrtPlugins::W3C;
118     std::stringstream str;
119     str << eventType;
120
121     // if needed, arguments for event should be set here
122     if (eventType == SoftKeyboardChangeCustomEvent) {
123         if (data) {
124             SoftKeyboardChangeArgs* args =
125                 static_cast<SoftKeyboardChangeArgs *>(data);
126             str << " " << args->state;
127             str << " " << args->width;
128             str << " " << args->height;
129         }
130     }
131
132     std::string msgString = str.str();
133     const char* msg = msgString.c_str();
134     const char* name = Message::ToInjectedBundle::DISPATCH_JS_EVENT;
135
136     ewk_context_message_post_to_injected_bundle(ewkContext, name, msg);
137 }
138
139 void setXwindowHandle(Ewk_Context* ewkContext, const unsigned int handle)
140 {
141     const char* name = Message::ToInjectedBundle::SET_XWINDOW_HANDLE;
142     std::stringstream ssMsg;
143     ssMsg << handle;
144     std::string msgString = ssMsg.str();
145     const char* msg = msgString.c_str();
146
147     ewk_context_message_post_to_injected_bundle(ewkContext, name, msg);
148 }
149
150 void setViewmodes(Ewk_Context* ewkContext, const char* msg)
151 {
152     const char* name = Message::ToInjectedBundle::SET_VIEWMODES;
153     ewk_context_message_post_to_injected_bundle(ewkContext, name, msg);
154 }
155 } // namespace ViewLogicMessageSupport