Commit bedac6ee authored by commit-queue@webkit.org's avatar commit-queue@webkit.org
Browse files

[EFL][WK2] Add support for getting page contents as string

https://bugs.webkit.org/show_bug.cgi?id=106752

Patch by KwangYong Choi <ky0.choi@samsung.com> on 2013-04-04
Reviewed by Andreas Kling.

Modified ewk_view_page_contents_get() API to get page contents as string.
EWK_PAGE_CONTENTS_TYPE_STRING is added to Ewk_Page_Contents_Type.
Now, we can use both EWK_PAGE_CONTENTS_TYPE_MHTML and EWK_PAGE_CONTENTS_TYPE_STRING
for getting page contents.

* UIProcess/API/efl/ewk_view.cpp:
(Ewk_Page_Contents_Context):
(ewkViewPageContentsAsMHTMLCallback):
(ewkViewPageContentsAsStringCallback):
(ewk_view_page_contents_get):
* UIProcess/API/efl/ewk_view.h:
* UIProcess/API/efl/tests/test_ewk2_view.cpp:
(PageContentsAsMHTMLCallback):
(PageContentsAsStringCallback):
(TEST_F):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@147700 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 75f883a0
2013-04-04 KwangYong Choi <ky0.choi@samsung.com>
[EFL][WK2] Add support for getting page contents as string
https://bugs.webkit.org/show_bug.cgi?id=106752
Reviewed by Andreas Kling.
Modified ewk_view_page_contents_get() API to get page contents as string.
EWK_PAGE_CONTENTS_TYPE_STRING is added to Ewk_Page_Contents_Type.
Now, we can use both EWK_PAGE_CONTENTS_TYPE_MHTML and EWK_PAGE_CONTENTS_TYPE_STRING
for getting page contents.
* UIProcess/API/efl/ewk_view.cpp:
(Ewk_Page_Contents_Context):
(ewkViewPageContentsAsMHTMLCallback):
(ewkViewPageContentsAsStringCallback):
(ewk_view_page_contents_get):
* UIProcess/API/efl/ewk_view.h:
* UIProcess/API/efl/tests/test_ewk2_view.cpp:
(PageContentsAsMHTMLCallback):
(PageContentsAsStringCallback):
(TEST_F):
2013-04-04 Christophe Dumez <ch.dumez@sisa.samsung.com>
 
[Cairo] Stop passing raw pointers to BitmapImage::create()
......@@ -535,36 +535,59 @@ typedef struct Ewk_Page_Contents_Context Ewk_Page_Contents_Context;
struct Ewk_Page_Contents_Context {
Ewk_Page_Contents_Type type;
Ewk_Page_Contents_Cb callback;
void* userData;
};
/**
* @internal
* Callback function used for ewk_view_page_contents_get().
*/
static void ewkViewPageContentsCallback(WKDataRef wkData, WKErrorRef, void* context)
static void ewkViewPageContentsAsMHTMLCallback(WKDataRef wkData, WKErrorRef, void* context)
{
EINA_SAFETY_ON_NULL_RETURN(context);
Ewk_Page_Contents_Context* contentsContext= static_cast<Ewk_Page_Contents_Context*>(context);
contentsContext->callback(contentsContext->type, reinterpret_cast<const char*>(WKDataGetBytes(wkData)));
Ewk_Page_Contents_Context* contentsContext = static_cast<Ewk_Page_Contents_Context*>(context);
contentsContext->callback(contentsContext->type, reinterpret_cast<const char*>(WKDataGetBytes(wkData)), contentsContext->userData);
delete contentsContext;
}
Eina_Bool ewk_view_page_contents_get(const Evas_Object* ewkView, Ewk_Page_Contents_Type type, Ewk_Page_Contents_Cb callback)
/**
* @internal
* Callback function used for ewk_view_page_contents_get().
*/
static void ewkViewPageContentsAsStringCallback(WKStringRef wkString, WKErrorRef, void* context)
{
EINA_SAFETY_ON_NULL_RETURN(context);
Ewk_Page_Contents_Context* contentsContext = static_cast<Ewk_Page_Contents_Context*>(context);
contentsContext->callback(contentsContext->type, WKEinaSharedString(wkString), contentsContext->userData);
delete contentsContext;
}
Eina_Bool ewk_view_page_contents_get(const Evas_Object* ewkView, Ewk_Page_Contents_Type type, Ewk_Page_Contents_Cb callback, void* user_data)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, false);
// We only support MHTML at the moment.
if (type != EWK_PAGE_CONTENTS_TYPE_MHTML)
return false;
Ewk_Page_Contents_Context* context = new Ewk_Page_Contents_Context;
context->type = type;
context->callback = callback;
WKPageGetContentsAsMHTMLData(impl->wkPage(), false, context, ewkViewPageContentsCallback);
context->userData = user_data;
switch (context->type) {
case EWK_PAGE_CONTENTS_TYPE_MHTML:
WKPageGetContentsAsMHTMLData(impl->wkPage(), false, context, ewkViewPageContentsAsMHTMLCallback);
break;
case EWK_PAGE_CONTENTS_TYPE_STRING:
WKPageGetContentsAsString(impl->wkPage(), context, ewkViewPageContentsAsStringCallback);
break;
default:
delete context;
ASSERT_NOT_REACHED();
return false;
}
return true;
}
......
......@@ -102,7 +102,8 @@ typedef enum {
/// Enum values containing page contents type values.
typedef enum {
EWK_PAGE_CONTENTS_TYPE_MHTML
EWK_PAGE_CONTENTS_TYPE_MHTML,
EWK_PAGE_CONTENTS_TYPE_STRING
} Ewk_Page_Contents_Type;
typedef struct Ewk_View_Smart_Data Ewk_View_Smart_Data;
......@@ -281,8 +282,9 @@ typedef enum {
*
* @param type type of the contents
* @param data string buffer of the contents
* @param user_data user data will be passed when ewk_view_page_contents_get is called
*/
typedef void (*Ewk_Page_Contents_Cb)(Ewk_Page_Contents_Type type, const char *data);
typedef void (*Ewk_Page_Contents_Cb)(Ewk_Page_Contents_Type type, const char *data, void *user_data);
/**
* Sets the smart class APIs, enabling view to be inherited.
......@@ -821,10 +823,11 @@ EAPI void ewk_view_draws_page_background_set(Evas_Object *o, Eina_Bool enabled);
* @param o view object to get the page contents
* @param type type of the page contents
* @param callback callback function to be called when the operation is finished
* @param user_data user data to be passed to the callback function
*
* @return @c EINA_TRUE on success or @c EINA_FALSE otherwise
*/
EAPI Eina_Bool ewk_view_page_contents_get(const Evas_Object *o, Ewk_Page_Contents_Type type, Ewk_Page_Contents_Cb callback);
EAPI Eina_Bool ewk_view_page_contents_get(const Evas_Object *o, Ewk_Page_Contents_Type type, Ewk_Page_Contents_Cb callback, void *user_data);
/**
* Sets the source mode as EINA_TRUE to display the web source code
......
......@@ -926,7 +926,7 @@ TEST_F(EWK2UnitTestBase, ewk_view_contents_size_changed)
static bool obtainedPageContents = false;
static void PageContentsCallback(Ewk_Page_Contents_Type type, const char* data)
static void PageContentsAsMHTMLCallback(Ewk_Page_Contents_Type type, const char* data, void*)
{
// Check the type
ASSERT_EQ(EWK_PAGE_CONTENTS_TYPE_MHTML, type);
......@@ -943,13 +943,29 @@ static void PageContentsCallback(Ewk_Page_Contents_Type type, const char* data)
obtainedPageContents = true;
}
static void PageContentsAsStringCallback(Ewk_Page_Contents_Type type, const char* data, void*)
{
// Check the type.
ASSERT_EQ(EWK_PAGE_CONTENTS_TYPE_STRING, type);
// The variable data should be "Simple HTML".
ASSERT_STREQ("Simple HTML", data);
obtainedPageContents = true;
}
TEST_F(EWK2UnitTestBase, ewk_view_page_contents_get)
{
const char content[] = "<p>Simple HTML</p>";
ewk_view_html_string_load(webView(), content, 0, 0);
waitUntilLoadFinished();
ASSERT_TRUE(ewk_view_page_contents_get(webView(), EWK_PAGE_CONTENTS_TYPE_MHTML, PageContentsCallback));
ASSERT_TRUE(ewk_view_page_contents_get(webView(), EWK_PAGE_CONTENTS_TYPE_MHTML, PageContentsAsMHTMLCallback, 0));
while (!obtainedPageContents)
ecore_main_loop_iterate();
obtainedPageContents = false;
ASSERT_TRUE(ewk_view_page_contents_get(webView(), EWK_PAGE_CONTENTS_TYPE_STRING, PageContentsAsStringCallback, 0));
while (!obtainedPageContents)
ecore_main_loop_iterate();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment