1/* 2 * Copyright (C) 2012 Samsung Electronics 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include "config.h" 29#include "NavigatorContentUtilsClientEfl.h" 30 31#if ENABLE(NAVIGATOR_CONTENT_UTILS) 32 33#include "ewk_custom_handler_private.h" 34#include <wtf/text/CString.h> 35 36namespace WebCore { 37 38static Ewk_Custom_Handler_Data* customHandlerDataCreate(Evas_Object* ewkView, const char* scheme, const char* baseURL, const char* url) 39{ 40 Ewk_Custom_Handler_Data* data = new Ewk_Custom_Handler_Data; 41 data->ewkView = ewkView; 42 data->scheme = eina_stringshare_add(scheme); 43 data->base_url = eina_stringshare_add(baseURL); 44 data->url = eina_stringshare_add(url); 45 return data; 46} 47 48static void customHandlerDataDelete(Ewk_Custom_Handler_Data* data) 49{ 50 eina_stringshare_del(data->scheme); 51 eina_stringshare_del(data->base_url); 52 eina_stringshare_del(data->url); 53 delete data; 54} 55 56PassOwnPtr<NavigatorContentUtilsClientEfl> NavigatorContentUtilsClientEfl::create(Evas_Object* view) 57{ 58 return adoptPtr(new NavigatorContentUtilsClientEfl(view)); 59} 60 61NavigatorContentUtilsClientEfl::NavigatorContentUtilsClientEfl(Evas_Object* view) 62 : m_view(view) 63{ 64} 65 66void NavigatorContentUtilsClientEfl::registerProtocolHandler(const String& scheme, const String& baseURL, const String& url, const String& title) 67{ 68 Ewk_Custom_Handler_Data* data = customHandlerDataCreate(m_view, scheme.utf8().data(), baseURL.utf8().data(), url.utf8().data()); 69 data->title = eina_stringshare_add(title.utf8().data()); 70 ewk_custom_handler_register_protocol_handler(data); 71 eina_stringshare_del(data->title); 72 customHandlerDataDelete(data); 73} 74 75#if ENABLE(CUSTOM_SCHEME_HANDLER) 76NavigatorContentUtilsClient::CustomHandlersState NavigatorContentUtilsClientEfl::isProtocolHandlerRegistered(const String& scheme, const String& baseURL, const String& url) 77{ 78 Ewk_Custom_Handler_Data* data = customHandlerDataCreate(m_view, scheme.utf8().data(), baseURL.utf8().data(), url.utf8().data()); 79 NavigatorContentUtilsClient::CustomHandlersState result = static_cast<CustomHandlersState>(ewk_custom_handler_register_protocol_handler(data)); 80 customHandlerDataDelete(data); 81 82 return result; 83} 84 85void NavigatorContentUtilsClientEfl::unregisterProtocolHandler(const String& scheme, const String& baseURL, const String& url) 86{ 87 Ewk_Custom_Handler_Data* data = customHandlerDataCreate(m_view, scheme.utf8().data(), baseURL.utf8().data(), url.utf8().data()); 88 ewk_custom_handler_register_protocol_handler(data); 89 customHandlerDataDelete(data); 90} 91#endif 92 93} 94 95#endif // ENABLE(NAVIGATOR_CONTENT_UTILS) 96