[M69 Dev][TV] Support URL parsing for web app
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / wrt / wrt_dynamicplugin.cc
1 // Copyright 2014 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "wrt/wrt_dynamicplugin.h"
6
7 #include <dlfcn.h>
8
9 #include "base/command_line.h"
10 #include "base/logging.h"
11 #include "common/content_switches_efl.h"
12
13 namespace {
14
15 const char* const SET_WIDGET_INFO_FUNCTION = "DynamicSetWidgetInfo";
16 const char* const DATABASE_ATTACH_FUNCTION = "DynamicDatabaseAttach";
17 #if defined(OS_TIZEN_TV_PRODUCT)
18 const char* const URL_PARSING_FUNCTION = "DynamicTVUrlParsing";
19 #else
20 const char* const URL_PARSING_FUNCTION = "DynamicUrlParsing";
21 #endif
22
23 typedef void (*StartSessionFun_v0)(const char* tizen_app_id,
24                                    v8::Handle<v8::Context> context,
25                                    int routing_handle,
26                                    double scale_factor,
27                                    const char* encoded_bundle,
28                                    const char* theme,
29                                    const char* baseURL);
30 }  // namespace
31
32 WrtDynamicPlugin::WrtDynamicPlugin()
33     : DynamicPlugin(),
34       parseURL_(0),
35       set_widget_info_(0),
36       database_attach_(0),
37       on_IPC_message_(0) {
38   *reinterpret_cast<void**>(&parseURL_) = dlsym(handle_, URL_PARSING_FUNCTION);
39   if (!parseURL_)
40     LOG(ERROR) << "No " << URL_PARSING_FUNCTION << " symbol found!\n";
41
42   *reinterpret_cast<void**>(&set_widget_info_) =
43       dlsym(handle_, SET_WIDGET_INFO_FUNCTION);
44   if (!set_widget_info_)
45     LOG(ERROR) << "No " << SET_WIDGET_INFO_FUNCTION << " symbol found!";
46
47   *reinterpret_cast<void**>(&database_attach_) =
48       dlsym(handle_, DATABASE_ATTACH_FUNCTION);
49   if (!database_attach_) {
50     LOG(ERROR) << "No " << DATABASE_ATTACH_FUNCTION << " symbol found!\n";
51     return;
52   }
53
54   *reinterpret_cast<void**>(&on_IPC_message_) =
55       dlsym(handle_, "DynamicOnIPCMessage");
56   if (!on_IPC_message_)
57     LOG(ERROR) << "No DynamicOnIPCMessage symbol found!\n";
58   database_attach_(1);
59 }
60
61 void WrtDynamicPlugin::StartSession(const char* tizen_app_id,
62                                     v8::Handle<v8::Context> context,
63                                     int routing_handle,
64                                     double scale_factor,
65                                     const char* encoded_bundle,
66                                     const char* theme,
67                                     const char* baseURL) {
68   if (!start_session_ || !database_attach_)
69     return;
70   switch (version_) {
71     case 0: {
72       auto startSession_v0 =
73           reinterpret_cast<StartSessionFun_v0>(start_session_);
74       startSession_v0(tizen_app_id, context, routing_handle, scale_factor,
75                       encoded_bundle, theme, baseURL);
76       break;
77     }
78     case 1: {
79       DynamicPlugin::StartSession(tizen_app_id, context, routing_handle,
80                                   baseURL);
81       break;
82     }
83     default:
84       return;
85   }
86 }
87
88 void WrtDynamicPlugin::StopSession(const char* tizen_app_id,
89                                    v8::Handle<v8::Context> context) {
90   if (!stop_session_ || !database_attach_)
91     return;
92
93   DynamicPlugin::StopSession(tizen_app_id, context);
94 }
95
96 void WrtDynamicPlugin::ParseURL(std::string* old_url,
97                                 std::string* new_url,
98                                 const char* tizen_app_id,
99                                 bool* is_encrypted_file) {
100   if (!parseURL_ || !database_attach_)
101     return;
102
103 #if defined(OS_TIZEN_TV_PRODUCT)
104   parseURL_(old_url, new_url, tizen_app_id, is_encrypted_file);
105 #else
106   parseURL_(old_url, new_url, tizen_app_id);
107 #endif
108 }
109
110 void WrtDynamicPlugin::SetWidgetInfo(const std::string& tizen_app_id) {
111   if (!set_widget_info_)
112     return;
113
114   set_widget_info_(tizen_app_id.c_str());
115 }
116
117 WrtDynamicPlugin::~WrtDynamicPlugin() {
118   if (database_attach_)
119     database_attach_(0);
120 }
121
122 WrtDynamicPlugin& WrtDynamicPlugin::instance() {
123   static WrtDynamicPlugin dynamicPlugin;
124   return dynamicPlugin;
125 }
126
127 void WrtDynamicPlugin::MessageReceived(const Ewk_Wrt_Message_Data& data) {
128   if (!on_IPC_message_)
129     return;
130
131   on_IPC_message_(data);
132 }