2 Copyright (C) 2012 Samsung Electronics
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.
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.
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.
21 #include "ewk_form_data.h"
24 #include "WKAPICast.h"
26 #include "WKDictionary.h"
28 #include "WKRetainPtr.h"
31 #include <wtf/OwnArrayPtr.h>
32 #include <wtf/text/CString.h>
34 using namespace WebKit;
36 struct _Ewk_Form_Data {
48 static void freeFormValues(void* data)
50 EINA_SAFETY_ON_NULL_RETURN(data);
51 eina_stringshare_del(static_cast<char*>(data));
54 Ewk_Form_Data* ewkFormDataCreate(WKFrameRef frame, WKDictionaryRef values)
56 WKRetainPtr<WKArrayRef> keys(AdoptWK, WKDictionaryCopyKeys(values));
57 int size = WKArrayGetSize(keys.get());
58 Eina_Hash* formValues = eina_hash_string_small_new(freeFormValues);
59 for (int i = 0; i < size; i++) {
60 WKStringRef key = static_cast<WKStringRef>(WKArrayGetItemAtIndex(keys.get(), i));
61 if (WKGetTypeID(key) == WKStringGetTypeID()) {
62 WKStringRef value = static_cast<WKStringRef>(WKDictionaryGetItemForKey(values, key));
63 if (WKGetTypeID(value) == WKStringGetTypeID()) {
64 int length = WKStringGetMaximumUTF8CStringSize(key);
67 OwnArrayPtr<char> keyBuffer = adoptArrayPtr(new char[length]);
68 WKStringGetUTF8CString(key, keyBuffer.get(), length);
70 length = WKStringGetMaximumUTF8CStringSize(value);
73 OwnArrayPtr<char> valueBuffer = adoptArrayPtr(new char[length]);
74 WKStringGetUTF8CString(value, valueBuffer.get(), length);
75 eina_hash_add(formValues, keyBuffer.get(), eina_stringshare_add(valueBuffer.get()));
81 Ewk_Form_Data* formData = new Ewk_Form_Data;
82 formData->values = formValues;
83 WKRetainPtr<WKURLRef> wkUrl(AdoptWK, WKFrameCopyURL(frame));
85 formData->url = eina_stringshare_add(toImpl(wkUrl.get())->string().utf8().data());
90 void ewkFormDataDelete(Ewk_Form_Data* formData)
92 EINA_SAFETY_ON_NULL_RETURN(formData);
94 eina_stringshare_del(formData->url);
95 eina_hash_free(formData->values);
100 const char* ewk_form_data_url_get(Ewk_Form_Data* formData)
102 EINA_SAFETY_ON_NULL_RETURN_VAL(formData, 0);
103 return formData->url;
106 Eina_Hash* ewk_form_data_values_get(Ewk_Form_Data* formData)
108 EINA_SAFETY_ON_NULL_RETURN_VAL(formData, 0);
109 return formData->values;
112 #endif // #if OS(TIZEN)