Title: [139422] trunk/Source/WebKit2
Revision
139422
Author
[email protected]
Date
2013-01-11 02:31:42 -0800 (Fri, 11 Jan 2013)

Log Message

[EFL][WK2] Add ewk_view_page_contents_get() API
https://bugs.webkit.org/show_bug.cgi?id=106440

Patch by KwangYong Choi <[email protected]> on 2013-01-11
Reviewed by Gyuyoung Kim.

Add ewk_view_page_contents_get() API for getting contents of the current page.
Currently, it supports only MHTML type.

* UIProcess/API/efl/ewk_view.cpp:
(Ewk_Page_Contents_Context):
(ewkViewPageContentsCallback):
(ewk_view_page_contents_get):
* UIProcess/API/efl/ewk_view.h:
* UIProcess/API/efl/tests/test_ewk2_view.cpp:
(PageContentsCallback):
(TEST_F):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (139421 => 139422)


--- trunk/Source/WebKit2/ChangeLog	2013-01-11 10:30:15 UTC (rev 139421)
+++ trunk/Source/WebKit2/ChangeLog	2013-01-11 10:31:42 UTC (rev 139422)
@@ -1,3 +1,22 @@
+2013-01-11  KwangYong Choi  <[email protected]>
+
+        [EFL][WK2] Add ewk_view_page_contents_get() API
+        https://bugs.webkit.org/show_bug.cgi?id=106440
+
+        Reviewed by Gyuyoung Kim.
+
+        Add ewk_view_page_contents_get() API for getting contents of the current page.
+        Currently, it supports only MHTML type.
+
+        * UIProcess/API/efl/ewk_view.cpp:
+        (Ewk_Page_Contents_Context):
+        (ewkViewPageContentsCallback):
+        (ewk_view_page_contents_get):
+        * UIProcess/API/efl/ewk_view.h:
+        * UIProcess/API/efl/tests/test_ewk2_view.cpp:
+        (PageContentsCallback):
+        (TEST_F):
+
 2013-01-11  Krzysztof Czech  <[email protected]>
 
         [WK2] Missing HAVE(ACCESSIBILITY) guards to some atk/ accessibility files.

Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp (139421 => 139422)


--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp	2013-01-11 10:30:15 UTC (rev 139421)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp	2013-01-11 10:31:42 UTC (rev 139422)
@@ -39,6 +39,7 @@
 #include "WKRetainPtr.h"
 #include "WKString.h"
 #include "WebContext.h"
+#include "WebData.h"
 #include "WebFullScreenManagerProxy.h"
 #include "WebPageGroup.h"
 #include "WebPreferences.h"
@@ -145,6 +146,17 @@
         }                                                                      \
     } while (0)
 
+/// Creates a type name for Ewk_Page_Contents_Context.
+typedef struct Ewk_Page_Contents_Context Ewk_Page_Contents_Context;
+
+/*
+ * @brief Structure containing page contents context used for ewk_view_page_contents_get() API.
+ */
+struct Ewk_Page_Contents_Context {
+    Ewk_Page_Contents_Type type;
+    Ewk_Page_Contents_Cb callback;
+};
+
 static void _ewk_view_smart_changed(Ewk_View_Smart_Data* smartData)
 {
     if (smartData->changed.any)
@@ -938,3 +950,36 @@
 
     impl->setDrawsBackground(enabled);
 }
+
+/**
+ * @internal
+ * Callback function used for ewk_view_page_contents_get().
+ */
+static void ewkViewPageContentsCallback(WKDataRef wkData, WKErrorRef, void* context)
+{
+    EINA_SAFETY_ON_NULL_RETURN(context);
+
+    RefPtr<WebData> webData = toImpl(wkData);
+    Ewk_Page_Contents_Context* contentsContext= static_cast<Ewk_Page_Contents_Context*>(context);
+    contentsContext->callback(contentsContext->type, reinterpret_cast<const char*>(webData->bytes()));
+
+    delete contentsContext;
+}
+
+Eina_Bool ewk_view_page_contents_get(const Evas_Object* ewkView, Ewk_Page_Contents_Type type, Ewk_Page_Contents_Cb callback)
+{
+    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;
+
+    impl->page()->getContentsAsMHTMLData(DataCallback::create(context, ewkViewPageContentsCallback), false);
+
+    return true;
+}

Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.h (139421 => 139422)


--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.h	2013-01-11 10:30:15 UTC (rev 139421)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.h	2013-01-11 10:31:42 UTC (rev 139422)
@@ -107,6 +107,11 @@
     EWK_TEXT_DIRECTION_LEFT_TO_RIGHT
 } Ewk_Text_Direction;
 
+/// Enum values containing page contents type values.
+typedef enum {
+    EWK_PAGE_CONTENTS_TYPE_MHTML
+} Ewk_Page_Contents_Type;
+
 typedef struct Ewk_View_Smart_Data Ewk_View_Smart_Data;
 typedef struct Ewk_View_Smart_Class Ewk_View_Smart_Class;
 
@@ -315,6 +320,14 @@
 } Ewk_Pagination_Mode;
 
 /**
+ * Creates a type name for the callback function used to get the page contents.
+ *
+ * @param type type of the contents
+ * @param data string buffer of the contents
+ */
+typedef void (*Ewk_Page_Contents_Cb)(Ewk_Page_Contents_Type type, const char *data);
+
+/**
  * Sets the smart class APIs, enabling view to be inherited.
  *
  * @param api class definition to set, all members with the
@@ -846,6 +859,17 @@
  */
 EAPI void ewk_view_draws_page_background_set(Evas_Object *o, Eina_Bool enabled);
 
+/**
+ * Get contents of the current web page.
+ *
+ * @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
+ *
+ * @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);
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp (139421 => 139422)


--- trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp	2013-01-11 10:30:15 UTC (rev 139421)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp	2013-01-11 10:31:42 UTC (rev 139422)
@@ -916,3 +916,32 @@
 
     evas_object_smart_callback_del(webView(), "contents,size,changed", onContentsSizeChanged);
 }
+
+static bool isObtainedPageContents = false;
+
+static void PageContentsCallback(Ewk_Page_Contents_Type type, const char* data)
+{
+    // Check the type
+    ASSERT_EQ(EWK_PAGE_CONTENTS_TYPE_MHTML, type);
+
+    // The variable data should have below text block.
+    const char lines[] = "<=00h=00t=00m=00l=00>=00<=00h=00e=00a=00d=00>=00<=00m=00e=00t=00a=00 =00c=\r\n"
+        "=00h=00a=00r=00s=00e=00t=00=3D=00\"=00U=00T=00F=00-=001=006=00L=00E=00\"=00>=\r\n"
+        "=00<=00/=00h=00e=00a=00d=00>=00<=00b=00o=00d=00y=00>=00<=00p=00>=00S=00i=00=\r\n"
+        "m=00p=00l=00e=00 =00H=00T=00M=00L=00<=00/=00p=00>=00<=00/=00b=00o=00d=00y=\r\n"
+        "=00>=00<=00/=00h=00t=00m=00l=00>=00";
+    ASSERT_EQ(0, strncmp(data + 359, lines, strlen(lines)));
+
+    isObtainedPageContents = 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));
+    while (!isObtainedPageContents)
+        ecore_main_loop_iterate();
+}
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to