2 * Copyright (C) 2012 Intel Corporation. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "ewk_intent.h"
29 #include "WKAPICast.h"
31 #include "WKDictionary.h"
34 #include "ewk_intent_private.h"
35 #include <wtf/text/CString.h>
37 using namespace WebKit;
39 #if ENABLE(WEB_INTENTS)
40 Ewk_Intent::Ewk_Intent(WKIntentDataRef intentRef)
41 : m_wkIntent(intentRef)
42 , m_action(AdoptWK, WKIntentDataCopyAction(intentRef))
43 , m_type(AdoptWK, WKIntentDataCopyType(intentRef))
44 , m_service(AdoptWK, WKIntentDataCopyService(intentRef))
47 WebIntentData* Ewk_Intent::webIntentData() const
49 return toImpl(m_wkIntent.get());
52 const char* Ewk_Intent::action() const
57 const char* Ewk_Intent::type() const
62 const char* Ewk_Intent::service() const
67 WKRetainPtr<WKArrayRef> Ewk_Intent::suggestions() const
69 return adoptWK(WKIntentDataCopySuggestions(m_wkIntent.get()));
72 String Ewk_Intent::extra(const char* key) const
74 WKRetainPtr<WKStringRef> keyRef = adoptWK(WKStringCreateWithUTF8CString(key));
75 WKRetainPtr<WKStringRef> wkValue(AdoptWK, WKIntentDataCopyExtraValue(m_wkIntent.get(), keyRef.get()));
76 return toImpl(wkValue.get())->string();
79 WKRetainPtr<WKArrayRef> Ewk_Intent::extraKeys() const
81 WKRetainPtr<WKDictionaryRef> wkExtras(AdoptWK, WKIntentDataCopyExtras(m_wkIntent.get()));
82 return adoptWK(WKDictionaryCopyKeys(wkExtras.get()));
86 Ewk_Intent* ewk_intent_ref(Ewk_Intent* intent)
88 #if ENABLE(WEB_INTENTS)
89 EINA_SAFETY_ON_NULL_RETURN_VAL(intent, 0);
97 void ewk_intent_unref(Ewk_Intent* intent)
99 #if ENABLE(WEB_INTENTS)
100 EINA_SAFETY_ON_NULL_RETURN(intent);
106 const char* ewk_intent_action_get(const Ewk_Intent* intent)
108 EINA_SAFETY_ON_NULL_RETURN_VAL(intent, 0);
110 #if ENABLE(WEB_INTENTS)
111 return intent->action();
117 const char* ewk_intent_type_get(const Ewk_Intent* intent)
119 EINA_SAFETY_ON_NULL_RETURN_VAL(intent, 0);
121 #if ENABLE(WEB_INTENTS)
122 return intent->type();
128 const char* ewk_intent_service_get(const Ewk_Intent* intent)
130 EINA_SAFETY_ON_NULL_RETURN_VAL(intent, 0);
132 #if ENABLE(WEB_INTENTS)
133 return intent->service();
139 Eina_List* ewk_intent_suggestions_get(const Ewk_Intent* intent)
141 EINA_SAFETY_ON_NULL_RETURN_VAL(intent, 0);
143 #if ENABLE(WEB_INTENTS)
144 Eina_List* listOfSuggestions = 0;
145 WKRetainPtr<WKArrayRef> wkSuggestions = intent->suggestions();
146 const size_t numSuggestions = WKArrayGetSize(wkSuggestions.get());
147 for (size_t i = 0; i < numSuggestions; ++i) {
148 WKURLRef wkSuggestion = static_cast<WKURLRef>(WKArrayGetItemAtIndex(wkSuggestions.get(), i));
149 listOfSuggestions = eina_list_append(listOfSuggestions, eina_stringshare_add(toImpl(wkSuggestion)->string().utf8().data()));
152 return listOfSuggestions;
159 const char* ewk_intent_extra_get(const Ewk_Intent* intent, const char* key)
161 EINA_SAFETY_ON_NULL_RETURN_VAL(intent, 0);
163 #if ENABLE(WEB_INTENTS)
164 String value = intent->extra(key);
169 return eina_stringshare_add(value.utf8().data());
175 Eina_List* ewk_intent_extra_names_get(const Ewk_Intent* intent)
177 EINA_SAFETY_ON_NULL_RETURN_VAL(intent, 0);
179 #if ENABLE(WEB_INTENTS)
180 Eina_List* listOfKeys = 0;
181 WKRetainPtr<WKArrayRef> wkKeys = intent->extraKeys();
182 const size_t numKeys = WKArrayGetSize(wkKeys.get());
183 for (size_t i = 0; i < numKeys; ++i) {
184 WKStringRef wkKey = static_cast<WKStringRef>(WKArrayGetItemAtIndex(wkKeys.get(), i));
185 listOfKeys = eina_list_append(listOfKeys, eina_stringshare_add(toImpl(wkKey)->string().utf8().data()));