Create string tightly when retrive string from cbhm callback event
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / ewk_custom_handlers.cpp
1 /*
2     Copyright (C) 2012 Samsung Electronics
3
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21 #include "ewk_custom_handlers.h"
22
23 #if (ENABLE_TIZEN_REGISTER_PROTOCOL_HANDLER) || (ENABLE_TIZEN_REGISTER_CONTENT_HANDLER) || (ENABLE_TIZEN_CUSTOM_SCHEME_HANDLER)
24 #include "ewk_view_private.h"
25
26 struct _Ewk_Custom_Handlers_Data {
27     const char* target;
28     const char* base_url;
29     const char* url;
30     const char* title;
31     Ewk_Custom_Handlers_State result;
32 };
33
34 const char* ewk_custom_handlers_data_target_get(Ewk_Custom_Handlers_Data* customHandlersData)
35 {
36     EINA_SAFETY_ON_NULL_RETURN_VAL(customHandlersData, 0);
37
38     return customHandlersData->target;
39 }
40
41 const char* ewk_custom_handlers_data_base_url_get(Ewk_Custom_Handlers_Data* customHandlersData)
42 {
43     EINA_SAFETY_ON_NULL_RETURN_VAL(customHandlersData, 0);
44
45     return customHandlersData->base_url;
46 }
47
48 const char* ewk_custom_handlers_data_url_get(Ewk_Custom_Handlers_Data* customHandlersData)
49 {
50     EINA_SAFETY_ON_NULL_RETURN_VAL(customHandlersData, 0);
51
52     return customHandlersData->url;
53 }
54
55 const char* ewk_custom_handlers_data_title_get(Ewk_Custom_Handlers_Data* customHandlersData)
56 {
57     EINA_SAFETY_ON_NULL_RETURN_VAL(customHandlersData, 0);
58
59     return customHandlersData->title;
60 }
61
62 void ewk_custom_handlers_data_result_set(Ewk_Custom_Handlers_Data* customHandlersData, Ewk_Custom_Handlers_State result)
63 {
64     EINA_SAFETY_ON_NULL_RETURN(customHandlersData);
65
66     customHandlersData->result = result;
67 }
68
69 Ewk_Custom_Handlers_State ewkGetCustomHandlersDataResult(Ewk_Custom_Handlers_Data* customHandlersData)
70 {
71     EINA_SAFETY_ON_NULL_RETURN_VAL(customHandlersData, EWK_CUSTOM_HANDLERS_DECLINED);
72
73     return customHandlersData->result;
74 }
75
76 Ewk_Custom_Handlers_Data* ewkCustomHandlersCreateData(const char* target, const char* baseUrl, const char* url, const char* title)
77 {
78     Ewk_Custom_Handlers_Data* customHandlersData = new Ewk_Custom_Handlers_Data;
79     customHandlersData->target = eina_stringshare_add(target);
80     customHandlersData->base_url = eina_stringshare_add(baseUrl);
81     customHandlersData->url = eina_stringshare_add(url);
82     customHandlersData->title = eina_stringshare_add(title);
83
84     return customHandlersData;
85 }
86
87 Ewk_Custom_Handlers_Data* ewkCustomHandlersCreateData(const char* target, const char* baseUrl, const char* url)
88 {
89     Ewk_Custom_Handlers_Data* customHandlersData = new Ewk_Custom_Handlers_Data;
90     customHandlersData->target = eina_stringshare_add(target);
91     customHandlersData->base_url = eina_stringshare_add(baseUrl);
92     customHandlersData->url = eina_stringshare_add(url);
93     customHandlersData->title = 0;
94
95     return customHandlersData;
96 }
97
98 void ewkCustomHandlersDeleteData(Ewk_Custom_Handlers_Data* customHandlersData)
99 {
100     eina_stringshare_del(customHandlersData->target);
101     eina_stringshare_del(customHandlersData->base_url);
102     eina_stringshare_del(customHandlersData->url);
103     if(customHandlersData->title)
104         eina_stringshare_del(customHandlersData->title);
105     delete customHandlersData;
106 }
107 #endif // #if (ENABLE_TIZEN_REGISTER_PROTOCOL_HANDLER) || (ENABLE_TIZEN_REGISTER_CONTENT_HANDLER) || (ENABLE_TIZEN_CUSTOM_SCHEME_HANDLER)