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_frame.h"
23 #include "WKAPICast.h"
26 #include "WKRetainPtr.h"
28 #include <wtf/text/CString.h>
30 using namespace WebKit;
31 using namespace WebCore;
33 typedef struct _Ewk_Frame_Callback_Context
36 Ewk_Frame_Source_Get_Callback frameSourceGetCallback;
40 } Ewk_Frame_Callback_Context;
42 static void getSourceCallback(WKStringRef source, WKErrorRef error, void* context)
44 EINA_SAFETY_ON_NULL_RETURN(context);
45 Ewk_Frame_Callback_Context* callbackContext = static_cast<Ewk_Frame_Callback_Context*>(context);
47 ASSERT(callbackContext->frameSourceGetCallback);
50 callbackContext->frameSourceGetCallback(callbackContext->frame, toImpl(source)->string().utf8().data(), callbackContext->userData);
52 callbackContext->frameSourceGetCallback(callbackContext->frame, 0, callbackContext->userData);
54 delete callbackContext;
57 Ewk_Frame_Ref ewk_frame_parent_get(Ewk_Frame_Ref frame)
59 EINA_SAFETY_ON_NULL_RETURN_VAL(frame, 0);
61 WKFrameRef wkFrame = static_cast<WKFrameRef>(frame);
62 return static_cast<Ewk_Frame_Ref>(WKFrameGetParentFrame(wkFrame));
65 Eina_Bool ewk_frame_source_get(Ewk_Frame_Ref frame, Ewk_Frame_Source_Get_Callback callback, void* user_data)
67 EINA_SAFETY_ON_NULL_RETURN_VAL(frame, false);
68 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
70 Ewk_Frame_Callback_Context* context = new Ewk_Frame_Callback_Context;
71 context->frameSourceGetCallback = callback;
72 context->frame = frame;
73 context->userData = user_data;
74 WKFrameRef wkFrame = static_cast<WKFrameRef>(frame);
75 WKPageGetSourceForFrame(WKFrameGetPage(wkFrame), wkFrame, context, getSourceCallback);
80 Eina_Bool ewk_frame_can_show_mime_type(Ewk_Frame_Ref frame, char* mimeType)
82 EINA_SAFETY_ON_NULL_RETURN_VAL(frame, false);
83 EINA_SAFETY_ON_NULL_RETURN_VAL(mimeType, false);
85 WKFrameRef wkFrame = static_cast<WKFrameRef>(frame);
86 WKRetainPtr<WKStringRef> mimeTypeRef(AdoptWK, WKStringCreateWithUTF8CString(mimeType));
87 return WKFrameCanShowMIMEType(wkFrame, mimeTypeRef.get());
90 Eina_Bool ewk_frame_is_main_frame(Ewk_Frame_Ref frame)
92 EINA_SAFETY_ON_NULL_RETURN_VAL(frame, false);
94 WKFrameRef wkFrame = static_cast<WKFrameRef>(frame);
95 return WKFrameIsMainFrame(wkFrame);