Create string tightly when retrive string from cbhm callback event
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / ewk_frame.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_frame.h"
22
23 #include "WKAPICast.h"
24 #include "WKFrame.h"
25 #include "WKPage.h"
26 #include "WKRetainPtr.h"
27 #include "WKString.h"
28 #include <wtf/text/CString.h>
29
30 using namespace WebKit;
31 using namespace WebCore;
32
33 typedef struct _Ewk_Frame_Callback_Context
34 {
35     union {
36         Ewk_Frame_Source_Get_Callback frameSourceGetCallback;
37     };
38     Ewk_Frame_Ref frame;
39     void* userData;
40 } Ewk_Frame_Callback_Context;
41
42 static void getSourceCallback(WKStringRef source, WKErrorRef error, void* context)
43 {
44     EINA_SAFETY_ON_NULL_RETURN(context);
45     Ewk_Frame_Callback_Context* callbackContext = static_cast<Ewk_Frame_Callback_Context*>(context);
46
47     ASSERT(callbackContext->frameSourceGetCallback);
48
49     if (source)
50         callbackContext->frameSourceGetCallback(callbackContext->frame, toImpl(source)->string().utf8().data(), callbackContext->userData);
51     else
52         callbackContext->frameSourceGetCallback(callbackContext->frame, 0, callbackContext->userData);
53
54     delete callbackContext;
55 }
56
57 Ewk_Frame_Ref ewk_frame_parent_get(Ewk_Frame_Ref frame)
58 {
59     EINA_SAFETY_ON_NULL_RETURN_VAL(frame, 0);
60
61     WKFrameRef wkFrame = static_cast<WKFrameRef>(frame);
62     return static_cast<Ewk_Frame_Ref>(WKFrameGetParentFrame(wkFrame));
63 }
64
65 Eina_Bool ewk_frame_source_get(Ewk_Frame_Ref frame, Ewk_Frame_Source_Get_Callback callback, void* user_data)
66 {
67     EINA_SAFETY_ON_NULL_RETURN_VAL(frame, false);
68     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
69
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);
76
77     return true;
78 }
79
80 Eina_Bool ewk_frame_can_show_mime_type(Ewk_Frame_Ref frame, char* mimeType)
81 {
82     EINA_SAFETY_ON_NULL_RETURN_VAL(frame, false);
83     EINA_SAFETY_ON_NULL_RETURN_VAL(mimeType, false);
84
85     WKFrameRef wkFrame = static_cast<WKFrameRef>(frame);
86     WKRetainPtr<WKStringRef> mimeTypeRef(AdoptWK, WKStringCreateWithUTF8CString(mimeType));
87     return WKFrameCanShowMIMEType(wkFrame, mimeTypeRef.get());
88 }
89
90 Eina_Bool ewk_frame_is_main_frame(Ewk_Frame_Ref frame)
91 {
92     EINA_SAFETY_ON_NULL_RETURN_VAL(frame, false);
93
94     WKFrameRef wkFrame = static_cast<WKFrameRef>(frame);
95     return WKFrameIsMainFrame(wkFrame);
96 }