5f615809f7e0a33e0f53d0905b1ba3e0afb4889b
[platform/framework/web/web-provider.git] / src / Core / Service / MessageManager.cpp
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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    MessageMenager.h
18  * @author  Yunchan Cho (yunchan.cho@samsung.com)
19  */
20
21 #include <string>
22 #include <Evas.h>
23 #include <ewk_view.h>
24 #include <Core/Util/Log.h>
25 #include "MessageManager.h"
26
27 namespace Service {
28
29 static const std::string jsFireWindowEventFunction("webprovider.fireAppWidgetEvent");
30 static const std::string jsPdMessageEvent("pdmessage");
31 static const std::string jsBoxMessageEvent("boxmessage");
32
33 MessageManager::MessageManager()
34 {
35     LogD("enter");
36 }
37
38 MessageManager::~MessageManager()
39 {
40     LogD("enter");
41 }
42
43 bool MessageManager::send(Evas_Object* webview, ReceiverType receiver, std::string& message)
44 {
45     LogD("enter");
46
47     std::string eventName;
48
49     // set message event name triggered by receiver
50     switch (receiver) {
51     case TO_BOX:
52         eventName = jsPdMessageEvent;
53         break;
54     case TO_PD:
55         eventName = jsBoxMessageEvent;
56         break;
57     default:
58         return false;
59     }
60
61     std::string script = jsFireWindowEventFunction;
62     script += "(\"";
63     script += eventName;
64     script += "\", \"";
65     script += message;
66     script +="\");";
67     LogD("calling javascript: %s", script.c_str());
68
69     // execute js code for sending message
70     ewk_view_script_execute(webview, script.c_str(), executeScriptCallback, this);
71
72     return true;
73 }
74
75 void MessageManager::executeScriptCallback(
76         Evas_Object* webview, const char* result, void* data)
77 {
78     LogD("enter");
79     std::string resultStr(result ? result : "null");
80     LogD("result: %s", resultStr.c_str());
81 }
82 } // Service