Title: [92948] trunk/Source/WebKit/efl
Revision
92948
Author
[email protected]
Date
2011-08-12 00:46:13 -0700 (Fri, 12 Aug 2011)

Log Message

[EFL] HTML Saving feature.
https://bugs.webkit.org/show_bug.cgi?id=55455

Patch by Grzegorz Czajkowski <[email protected]> on 2011-08-12
Reviewed by Antonio Gomes.

Gets the source and location of resources for document.
TODO:
1. Support others resources (css, plugins, media files).
2. Currently only HTML documents are supported.

* ewk/ewk_frame.cpp:
(ewk_frame_source_get):
(ewk_frame_resources_location_get):
* ewk/ewk_frame.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/efl/ChangeLog (92947 => 92948)


--- trunk/Source/WebKit/efl/ChangeLog	2011-08-12 07:08:33 UTC (rev 92947)
+++ trunk/Source/WebKit/efl/ChangeLog	2011-08-12 07:46:13 UTC (rev 92948)
@@ -1,3 +1,20 @@
+2011-08-12  Grzegorz Czajkowski  <[email protected]>
+
+        [EFL] HTML Saving feature.
+        https://bugs.webkit.org/show_bug.cgi?id=55455
+
+        Reviewed by Antonio Gomes.
+
+        Gets the source and location of resources for document.
+        TODO:
+        1. Support others resources (css, plugins, media files).
+        2. Currently only HTML documents are supported.
+
+        * ewk/ewk_frame.cpp:
+        (ewk_frame_source_get):
+        (ewk_frame_resources_location_get):
+        * ewk/ewk_frame.h:
+
 2011-08-10  Grzegorz Czajkowski  <[email protected]>
 
         [EFL] Return from _ewk_view_smart_add if smart data can not be allocated

Modified: trunk/Source/WebKit/efl/ewk/ewk_frame.cpp (92947 => 92948)


--- trunk/Source/WebKit/efl/ewk/ewk_frame.cpp	2011-08-12 07:08:33 UTC (rev 92947)
+++ trunk/Source/WebKit/efl/ewk/ewk_frame.cpp	2011-08-12 07:46:13 UTC (rev 92948)
@@ -31,6 +31,10 @@
 #include "FrameLoaderClientEfl.h"
 #include "FrameTree.h"
 #include "FrameView.h"
+#include "HTMLCollection.h"
+#include "HTMLHeadElement.h"
+#include "HTMLImageElement.h"
+#include "HTMLNames.h"
 #include "HTMLPlugInElement.h"
 #include "HistoryItem.h"
 #include "HitTestResult.h"
@@ -1480,6 +1484,100 @@
     sd->frame->view()->setEvasObject(o);
 }
 
+ssize_t ewk_frame_source_get(Evas_Object *o, char **frame_source)
+{
+    EWK_FRAME_SD_GET_OR_RETURN(o, sd, -1);
+    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->frame, -1);
+    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->frame->document(), -1);
+    EINA_SAFETY_ON_NULL_RETURN_VAL(frame_source, -1);
+
+    WTF::String source;
+    *frame_source = 0; // Saves 0 to pointer until it's not allocated.
+
+    if (!sd->frame->document()->isHTMLDocument()) {
+        // FIXME: Support others documents.
+        WRN("Only HTML documents are supported");
+        return -1;
+    }
+
+    // Look for <html> tag. If it exists, the node contatins all document's source.
+    WebCore::Node *documentNode = sd->frame->document()->documentElement();
+    if (documentNode)
+        for (WebCore::Node *node = documentNode->firstChild(); node; node = node->parentElement()) {
+            if (node->hasTagName(WebCore::HTMLNames::htmlTag)) {
+                WebCore::HTMLElement *element = static_cast<WebCore::HTMLElement*>(node);
+                if (element)
+                    source = element->outerHTML();
+                break;
+            }
+        }
+
+    // Try to get <head> and <body> tags if <html> tag was not found.
+    if (source.isEmpty()) {
+        if (sd->frame->document()->head())
+            source = sd->frame->document()->head()->outerHTML();
+
+        if (sd->frame->document()->body())
+            source += sd->frame->document()->body()->outerHTML();
+    }
+
+    size_t source_length = strlen(source.utf8().data());
+    *frame_source = static_cast<char*>(malloc(source_length + 1));
+    if (!*frame_source) {
+        CRITICAL("Could not allocate memory.");
+        return -1;
+    }
+
+    strncpy(*frame_source, source.utf8().data(), source_length);
+    (*frame_source)[source_length] = '\0';
+
+    return source_length;
+}
+
+Eina_List *ewk_frame_resources_location_get(Evas_Object *o)
+{
+    EWK_FRAME_SD_GET_OR_RETURN(o, sd, 0);
+    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->frame, 0);
+    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->frame->document(), 0);
+
+    Eina_List *listOfImagesLocation = 0;
+
+    // Get src attibute of images and saves them to the Eina_List.
+    RefPtr<WebCore::HTMLCollection> images = sd->frame->document()->images();
+    for (size_t index = 0; index < images->length(); ++index) {
+        WebCore::HTMLImageElement *imageElement = static_cast<WebCore::HTMLImageElement*>(images->item(index));
+        if (!imageElement || imageElement->src().isNull() || imageElement->src().isEmpty())
+            continue;
+
+        WTF::String imageLocation = imageElement->src().string();
+        // Look for duplicated location.
+        Eina_List *listIterator = 0;
+        void *data = ""
+        Eina_Bool found = EINA_FALSE;
+        EINA_LIST_FOREACH(listOfImagesLocation, listIterator, data)
+            if (found = !strcmp(static_cast<char*>(data), imageLocation.utf8().data()))
+                break;
+        if (found)
+            continue;
+
+        char *imageLocationCopy = strdup(imageLocation.utf8().data());
+        if (!imageLocationCopy)
+            goto out_of_memory_handler;
+        listOfImagesLocation = eina_list_append(listOfImagesLocation, imageLocationCopy);
+        if (eina_error_get())
+            goto out_of_memory_handler;
+    }
+    // FIXME: Get URL others resources (plugins, css, media files).
+    return listOfImagesLocation;
+
+out_of_memory_handler:
+    CRITICAL("Could not allocate memory.");
+    void *data;
+    EINA_LIST_FREE(listOfImagesLocation, data)
+        free(data);
+    return 0;
+}
+
 /**
  * @internal
  * Reports uri changed and swap internal string reference.

Modified: trunk/Source/WebKit/efl/ewk/ewk_frame.h (92947 => 92948)


--- trunk/Source/WebKit/efl/ewk/ewk_frame.h	2011-08-12 07:08:33 UTC (rev 92947)
+++ trunk/Source/WebKit/efl/ewk/ewk_frame.h	2011-08-12 07:46:13 UTC (rev 92948)
@@ -765,7 +765,36 @@
  */
 EAPI Ewk_Text_Selection_Type ewk_frame_text_selection_type_get(Evas_Object *o);
 
+/**
+ * Gets the frame source.
+ *
+ * It's part of HTML saving feature. Currently only HTML documents are supported.
+ *
+ * @param o frame smart object to get the frame source
+ * @param frame_source a pointer to store the source of frame,
+ *        must @b not be @c 0, this value @b should be freed after use
+ *
+ * @return @c length of @a frame_source on success, or @c -1 on failure
+ *
+ * @see ewk_frame_resources_location_get()
+ */
+EAPI ssize_t ewk_frame_source_get(Evas_Object *o, char **frame_source);
 
+/**
+ * Gets the resource list of this frame.
+ *
+ * It's part of HTML saving feature. Currently only locations of images are supported.
+ * An application might find these values in frame source and
+ * replace them to the local paths. Values are not duplicated.
+ *
+ * @param o frame smart object to get the resources list
+ * @return @c Eina_List with location of resources on success, or @c 0 on failure,
+ *         the Eina_List should be freed after use
+ *
+ * @see ewk_frame_source_get()
+ */
+EAPI Eina_List *ewk_frame_resources_location_get(Evas_Object *o);
+
 #ifdef __cplusplus
 }
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to