[EFL] Expose JavaScript binding interface through ewk_extension
authorryuan.choi@navercorp.com <ryuan.choi@navercorp.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Mar 2015 02:42:30 +0000 (02:42 +0000)
committerryuan.choi@navercorp.com <ryuan.choi@navercorp.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Mar 2015 02:42:30 +0000 (02:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142033

Reviewed by Gyuyoung Kim.

.:

* Source/cmake/OptionsEfl.cmake: Added HEADER_INSTALL_DIR variable.

Source/JavaScriptCore:

* PlatformEfl.cmake: Install Javascript APIs.

Source/WebKit2:

* PlatformEfl.cmake:
* UIProcess/API/efl/tests/extensions/extension_sample.cpp: Registered test object for new test case.
* UIProcess/API/efl/tests/test_ewk2_javascript_binding.cpp: Added simple binding API test case.
(EWK2ContextTestWithExtension::messageReceivedCallback):
(EWK2ContextTestWithExtension::EWK2ContextTestWithExtension):
(TEST_F):
* WebProcess/InjectedBundle/API/efl/EWebKit_Extension.h:
* WebProcess/InjectedBundle/API/efl/ewk_extension.cpp:
(EwkExtension::didCreatePage):
(EwkExtension::willDestroyPage):
* WebProcess/InjectedBundle/API/efl/ewk_extension.h:
* WebProcess/InjectedBundle/API/efl/ewk_extension_private.h:
* WebProcess/InjectedBundle/API/efl/ewk_page.cpp: Added.
(toEwkPage):
(EwkPage::EwkPage):
(EwkPage::append):
(EwkPage::remove):
(EwkPage::didFinishDocumentLoadForFrame):
(ewk_page_js_global_context_get):
(ewk_page_client_register):
(ewk_page_client_unregister):
* WebProcess/InjectedBundle/API/efl/ewk_page.h: Added.
* WebProcess/InjectedBundle/API/efl/ewk_page_private.h: Added.
(EwkPage::page):
* efl/ewebkit2-extension.pc.in:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181681 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
ChangeLog
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/PlatformEfl.cmake
Source/WebKit2/ChangeLog
Source/WebKit2/PlatformEfl.cmake
Source/WebKit2/UIProcess/API/efl/tests/extensions/extension_sample.cpp
Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_javascript_binding.cpp [new file with mode: 0644]
Source/WebKit2/WebProcess/InjectedBundle/API/efl/EWebKit_Extension.h
Source/WebKit2/WebProcess/InjectedBundle/API/efl/ewk_extension.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/efl/ewk_extension.h
Source/WebKit2/WebProcess/InjectedBundle/API/efl/ewk_extension_private.h
Source/WebKit2/WebProcess/InjectedBundle/API/efl/ewk_page.cpp [new file with mode: 0644]
Source/WebKit2/WebProcess/InjectedBundle/API/efl/ewk_page.h [new file with mode: 0644]
Source/WebKit2/WebProcess/InjectedBundle/API/efl/ewk_page_private.h [new file with mode: 0644]
Source/WebKit2/efl/ewebkit2-extension.pc.in
Source/cmake/OptionsEfl.cmake

index 8077c69..cc6c9ae 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2015-03-17  Ryuan Choi  <ryuan.choi@navercorp.com>
+
+        [EFL] Expose JavaScript binding interface through ewk_extension
+        https://bugs.webkit.org/show_bug.cgi?id=142033
+
+        Reviewed by Gyuyoung Kim.
+
+        * Source/cmake/OptionsEfl.cmake: Added HEADER_INSTALL_DIR variable.
+
 2015-03-17  Philippe Normand  <pnormand@igalia.com>
 
         [GTK] basic OpenWebRTC build support
index 815d9aa..5652016 100644 (file)
@@ -1,3 +1,12 @@
+2015-03-17  Ryuan Choi  <ryuan.choi@navercorp.com>
+
+        [EFL] Expose JavaScript binding interface through ewk_extension
+        https://bugs.webkit.org/show_bug.cgi?id=142033
+
+        Reviewed by Gyuyoung Kim.
+
+        * PlatformEfl.cmake: Install Javascript APIs.
+
 2015-03-17  Geoffrey Garen  <ggaren@apple.com>
 
         Function bodies should always include braces
index 44f27ca..6cc8c0e 100644 (file)
@@ -4,3 +4,13 @@ list(APPEND JavaScriptCore_INCLUDE_DIRECTORIES
     ${EO_INCLUDE_DIRS}
 )
 add_definitions(-DSTATICALLY_LINKED_WITH_WTF)
+
+install(FILES API/JavaScript.h
+              API/JSBase.h
+              API/JSContextRef.h
+              API/JSObjectRef.h
+              API/JSStringRef.h
+              API/JSValueRef.h
+              API/WebKitAvailability.h
+        DESTINATION "${HEADER_INSTALL_DIR}/JavaScriptCore"
+)
index 4e0f807..a43c258 100644 (file)
@@ -1,3 +1,36 @@
+2015-03-17  Ryuan Choi  <ryuan.choi@navercorp.com>
+
+        [EFL] Expose JavaScript binding interface through ewk_extension
+        https://bugs.webkit.org/show_bug.cgi?id=142033
+
+        Reviewed by Gyuyoung Kim.
+
+        * PlatformEfl.cmake:
+        * UIProcess/API/efl/tests/extensions/extension_sample.cpp: Registered test object for new test case.
+        * UIProcess/API/efl/tests/test_ewk2_javascript_binding.cpp: Added simple binding API test case.
+        (EWK2ContextTestWithExtension::messageReceivedCallback):
+        (EWK2ContextTestWithExtension::EWK2ContextTestWithExtension):
+        (TEST_F):
+        * WebProcess/InjectedBundle/API/efl/EWebKit_Extension.h:
+        * WebProcess/InjectedBundle/API/efl/ewk_extension.cpp:
+        (EwkExtension::didCreatePage):
+        (EwkExtension::willDestroyPage):
+        * WebProcess/InjectedBundle/API/efl/ewk_extension.h:
+        * WebProcess/InjectedBundle/API/efl/ewk_extension_private.h:
+        * WebProcess/InjectedBundle/API/efl/ewk_page.cpp: Added.
+        (toEwkPage):
+        (EwkPage::EwkPage):
+        (EwkPage::append):
+        (EwkPage::remove):
+        (EwkPage::didFinishDocumentLoadForFrame):
+        (ewk_page_js_global_context_get):
+        (ewk_page_client_register):
+        (ewk_page_client_unregister):
+        * WebProcess/InjectedBundle/API/efl/ewk_page.h: Added.
+        * WebProcess/InjectedBundle/API/efl/ewk_page_private.h: Added.
+        (EwkPage::page):
+        * efl/ewebkit2-extension.pc.in:
+
 2015-03-17  Tim Horton  <timothy_horton@apple.com>
 
         Cannot invoke action menus anymore
index 8085f18..3a4f5f5 100644 (file)
@@ -179,6 +179,7 @@ list(APPEND WebKit2_SOURCES
     WebProcess/Cookies/soup/WebKitSoupCookieJarSqlite.cpp
 
     WebProcess/InjectedBundle/API/efl/ewk_extension.cpp
+    WebProcess/InjectedBundle/API/efl/ewk_page.cpp
 
     WebProcess/InjectedBundle/efl/InjectedBundleEfl.cpp
 
@@ -406,10 +407,11 @@ set(EWebKit2_HEADERS
 set(EWebKit2_Extension_HEADERS
     "${CMAKE_CURRENT_SOURCE_DIR}/WebProcess/InjectedBundle/API/efl/EWebKit_Extension.h"
     "${CMAKE_CURRENT_SOURCE_DIR}/WebProcess/InjectedBundle/API/efl/ewk_extension.h"
+    "${CMAKE_CURRENT_SOURCE_DIR}/WebProcess/InjectedBundle/API/efl/ewk_page.h"
 )
 
-install(FILES ${EWebKit2_HEADERS} DESTINATION include/${WebKit2_OUTPUT_NAME}-${PROJECT_VERSION_MAJOR})
-install(FILES ${EWebKit2_Extension_HEADERS} DESTINATION include/${WebKit2_OUTPUT_NAME}-${PROJECT_VERSION_MAJOR}/extension)
+install(FILES ${EWebKit2_HEADERS} DESTINATION ${HEADER_INSTALL_DIR})
+install(FILES ${EWebKit2_Extension_HEADERS} DESTINATION ${HEADER_INSTALL_DIR}/extension)
 
 install(FILES ${CMAKE_BINARY_DIR}/WebKit2/efl/ewebkit2.pc DESTINATION lib/pkgconfig)
 install(FILES ${CMAKE_BINARY_DIR}/WebKit2/efl/ewebkit2-extension.pc DESTINATION lib/pkgconfig)
@@ -510,6 +512,7 @@ set(EWK2UnitTests_BINARIES
     test_ewk2_eina_shared_string
     test_ewk2_favicon_database
     test_ewk2_file_chooser_request
+    test_ewk2_javascript_binding
     test_ewk2_object
     test_ewk2_page_group
     test_ewk2_popup_menu
index 2941343..7a5f5f7 100644 (file)
  */
 
 #include "EWebKit_Extension.h"
+#include <JavaScriptCore/JavaScript.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+static JSValueRef helloCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    Ewk_Extension* extension = static_cast<Ewk_Extension*>(JSObjectGetPrivate(thisObject));
+
+    Eina_Value* value = eina_value_new(EINA_VALUE_TYPE_STRING);
+    eina_value_set(value, "Hello from extension");
+    ewk_extension_message_post(extension, "hello", value);
+    eina_value_free(value);
+
+    return nullptr;
+}
+
+void loadFinished(Ewk_Page* page, void* data)
+{
+    JSGlobalContextRef jsContext = ewk_page_js_global_context_get(page);
+    JSObjectRef windowObject = JSContextGetGlobalObject(jsContext);
+
+    static JSStaticFunction functions[] = {
+        { "hello", helloCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { 0, 0, 0 }
+    };
+    static JSClassDefinition class_definition = {
+        0, kJSClassAttributeNone, "Test", 0, 0, functions,
+        0, 0/* */, 0, 0, 0, 0, 0, 0, 0, 0, 0
+    };
+    JSClassRef clasz = JSClassCreate(&class_definition);
+    JSObjectRef object = JSObjectMake(jsContext, clasz, data);
+    JSClassRelease(clasz);
+
+    JSObjectSetPrivate(object, data);
+
+    JSValueRef exception = 0;
+    JSStringRef property = JSStringCreateWithUTF8CString("test");
+    JSObjectSetProperty(jsContext, windowObject, property, object, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, &exception);
+    JSStringRelease(property);
+}
+
+static Ewk_Page_Client pageClient;
+
+static void pageAdded(Ewk_Page* page, void* data)
+{
+    pageClient.version = 1;
+    pageClient.data = data;
+    pageClient.load_finished = loadFinished;
+
+    ewk_page_client_register(page, &pageClient);
+}
+
+static void pageDelete(Ewk_Page* page, void*)
+{
+    ewk_page_client_unregister(page, &pageClient);
+}
+
 static void messageReceived(const char* name, const Eina_Value* body, void* data)
 {
     Eina_Value* value = eina_value_new(EINA_VALUE_TYPE_STRING);
@@ -42,6 +96,8 @@ void ewk_extension_init(Ewk_Extension* extension)
     static EwkExtensionClient client;
     client.version = 1;
     client.data = (void *)extension;
+    client.page_add = pageAdded;
+    client.page_del = pageDelete;
     client.message_received = messageReceived;
 
     ewk_extension_client_add(extension, &client);
diff --git a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_javascript_binding.cpp b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_javascript_binding.cpp
new file mode 100644 (file)
index 0000000..842d071
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2015 Ryuan Choi <ryuan.choi@gmail.com>.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "EwkView.h"
+#include "UnitTestUtils/EWK2UnitTestBase.h"
+
+using namespace EWK2UnitTest;
+
+extern EWK2UnitTestEnvironment* environment;
+
+static constexpr double testTimeoutSeconds = 2.0;
+
+class EWK2ContextTestWithExtension : public EWK2UnitTestBase {
+public:
+    static void messageReceivedCallback(const char* name, const Eina_Value* body, void* userData)
+    {
+        bool* handled = static_cast<bool*>(userData);
+        ASSERT_STREQ("hello", name);
+
+        *handled = true;
+    }
+
+protected:
+    EWK2ContextTestWithExtension()
+    {
+        m_withExtension = true;
+    }
+};
+
+TEST_F(EWK2ContextTestWithExtension, ewk_javascript_binding)
+{
+    bool received = false;
+    Ewk_Context* context = ewk_view_context_get(webView());
+
+    ewk_context_message_from_extensions_callback_set(context, messageReceivedCallback, &received);
+
+    ewk_view_url_set(webView(), environment->defaultTestPageUrl());
+    ASSERT_TRUE(waitUntilLoadFinished());
+
+    ewk_view_script_execute(webView(), "test.hello();", nullptr, nullptr);
+
+    ASSERT_TRUE(waitUntilTrue(received, testTimeoutSeconds));
+}
+
index 906001d..16e239d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Ryuan Choi <ryuan.choi@gmail.com>.  All rights reserved.
+ * Copyright (C) 2014-2015 Ryuan Choi <ryuan.choi@gmail.com>.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -57,5 +57,6 @@
 #define EWebKit_Extension_h
 
 #include "ewk_extension.h"
+#include "ewk_page.h"
 
 #endif // EWebKit_Extension_h
index 16f344f..13d34d9 100644 (file)
@@ -31,7 +31,9 @@
 #include "WKBundle.h"
 #include "WKBundleAPICast.h"
 #include "WKRetainPtr.h"
+#include "WebPage.h"
 #include "ewk_extension_private.h"
+#include "ewk_page_private.h"
 #include <WebKit/WKString.h>
 #include <WebKit/WKType.h>
 #include <wtf/text/CString.h>
@@ -70,14 +72,30 @@ void EwkExtension::remove(Ewk_Extension_Client* client)
     m_clients.removeFirst(client);
 }
 
-void EwkExtension::didCreatePage(WKBundleRef, WKBundlePageRef, const void*)
+void EwkExtension::didCreatePage(WKBundleRef, WKBundlePageRef wkPage, const void* clientInfo)
 {
-    notImplemented();
+    EwkExtension* self = toEwkExtendion(clientInfo);
+    WebPage* page = toImpl(wkPage);
+
+    auto ewkPage = std::make_unique<EwkPage>(page);
+    for (auto& it : self->m_clients) {
+        if (it->page_add)
+            it->page_add(ewkPage.get(), it->data);
+    }
+
+    self->m_pageMap.add(page, WTF::move(ewkPage));
 }
 
-void EwkExtension::willDestroyPage(WKBundleRef, WKBundlePageRef, const void*)
+void EwkExtension::willDestroyPage(WKBundleRef, WKBundlePageRef wkPage, const void* clientInfo)
 {
-    notImplemented();
+    EwkExtension* self = toEwkExtendion(clientInfo);
+    WebPage* page = toImpl(wkPage);
+
+    for (auto& it : self->m_clients) {
+        if (it->page_del)
+            it->page_del(self->m_pageMap.get(page), it->data);
+    }
+    self->m_pageMap.remove(page);
 }
 
 void EwkExtension::didReceiveMessage(WKBundleRef, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo)
index 4fa3ad1..bf1ee85 100644 (file)
@@ -38,6 +38,11 @@ extern "C" {
 #endif
 
 /**
+ * Declare Ewk_Page.
+ */
+typedef struct EwkPage Ewk_Page;
+
+/**
  * Declare Ewk_Extension.
  */
 typedef struct EwkExtension Ewk_Extension;
@@ -58,10 +63,27 @@ struct EwkExtensionClient {
     void *data;
 
     /**
+     * Callbacks to report page added.
+     *
+     * @param page page to be finished
+     * @param data data of a extension client
+     */
+    void (*page_add)(Ewk_Page* page, void *data);
+
+    /**
+     * Callbacks to report page will be removed.
+     *
+     * @param page page to be finished
+     * @param data data of a extension client
+     */
+    void (*page_del)(Ewk_Page* page, void *data);
+
+    /**
      * Callbacks to receive message from ewk_context.
      *
      * @param name name of message from ewk_context
      * @param body body of message from ewk_context
+     * @param data data of a extension client
      */
     void (*message_received)(const char *name, const Eina_Value *body, void *data);
 };
index d472769..8ffadd5 100644 (file)
 #ifndef ewk_extension_private_h
 #define ewk_extension_private_h
 
+#include "ewk_page_private.h"
 #include <wtf/Vector.h>
 
 namespace WebKit {
 class InjectedBundle;
+class WebPage;
 }
 
+class EwkPage;
+
 class EwkExtension {
 public:
     explicit EwkExtension(WebKit::InjectedBundle*);
@@ -51,6 +55,7 @@ private:
     WebKit::InjectedBundle* m_bundle;
 
     Vector<Ewk_Extension_Client*> m_clients;
+    HashMap<WebKit::WebPage*, std::unique_ptr<EwkPage>> m_pageMap;
 };
 
 #endif // ewk_extension_private_h
diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/efl/ewk_page.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/efl/ewk_page.cpp
new file mode 100644 (file)
index 0000000..6388d03
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2015 Ryuan Choi <ryuan.choi@gmail.com>.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ewk_page.h"
+
+#include "WKBundle.h"
+#include "WKBundleAPICast.h"
+#include "WKBundleFrame.h"
+#include "WebFrame.h"
+#include "WebPage.h"
+#include "ewk_page_private.h"
+
+using namespace WebKit;
+
+static inline EwkPage* toEwkPage(const void* clientInfo)
+{
+    return const_cast<EwkPage*>(static_cast<const EwkPage*>(clientInfo));
+}
+
+EwkPage::EwkPage(WebPage* page)
+    : m_page(page)
+{
+    WKBundlePageLoaderClientV7 loaderClient = {
+        {
+            7, // version
+            this, // clientInfo
+        },
+        0, // didStartProvisionalLoadForFrame,
+        0, // didReceiveServerRedirectForProvisionalLoadForFrame,
+        0, // didFailProvisionalLoadWithErrorForFrame
+        0, // didCommitLoadForFrame
+        didFinishDocumentLoadForFrame,
+        0, // didFinishLoadForFrame
+        0, // didFailLoadWithErrorForFrame
+        0, // didSameDocumentNavigationForFrame,
+        0, // didReceiveTitleForFrame
+        0, // didFirstLayoutForFrame
+        0, // didFirstVisuallyNonEmptyLayoutForFrame
+        0, // didRemoveFrameFromHierarchy
+        0, // didDisplayInsecureContentForFrame
+        0, // didRunInsecureContentForFrame
+        0, // didClearWindowObjectForFrame,
+        0, // didCancelClientRedirectForFrame
+        0, // willPerformClientRedirectForFrame
+        0, // didHandleOnloadEventsForFrame
+        0, // didLayoutForFrame
+        0, // didNewFirstVisuallyNonEmptyLayout
+        0, // didDetectXSSForFrame
+        0, // shouldGoToBackForwardListItem
+        0, // globalObjectIsAvailableForFrame
+        0, // willDisconnectDOMWindowExtensionFromGlobalObject
+        0, // didReconnectDOMWindowExtensionToGlobalObject
+        0, // willDestroyGlobalObjectForDOMWindowExtension
+        0, // didFinishProgress
+        0, // shouldForceUniversalAccessFromLocalURL
+        0, // didReceiveIntentForFrame_unavailable
+        0, // registerIntentServiceForFrame_unavailable
+        0, // didLayout
+        0, // featuresUsedInPage
+        0, // willLoadURLRequest
+        0, // willLoadDataRequest
+        0 // willDestroyFrame
+    };
+    WKBundlePageSetPageLoaderClient(toAPI(page), &loaderClient.base);
+}
+
+void EwkPage::append(const Ewk_Page_Client* client)
+{
+    m_clients.append(client);
+}
+
+void EwkPage::remove(const Ewk_Page_Client* client)
+{
+    m_clients.remove(m_clients.find(client));
+}
+
+void EwkPage::didFinishDocumentLoadForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKTypeRef*, const void* clientInfo)
+{
+    if (!WKBundleFrameIsMainFrame(frame))
+        return;
+
+    EwkPage* self = toEwkPage(clientInfo);
+    for (auto& it : self->m_clients) {
+        if (it->load_finished)
+            it->load_finished(self, it->data);
+    }
+}
+
+JSGlobalContextRef ewk_page_js_global_context_get(const Ewk_Page* ewkPage)
+{
+    EINA_SAFETY_ON_NULL_RETURN_VAL(ewkPage, nullptr);
+
+    WebFrame* coreFrame = ewkPage->page()->mainWebFrame();
+    if (!coreFrame)
+        return nullptr;
+
+    return coreFrame->jsContext();
+}
+
+void ewk_page_client_register(Ewk_Page* ewkPage, const Ewk_Page_Client* client)
+{
+    EINA_SAFETY_ON_NULL_RETURN(ewkPage);
+    EINA_SAFETY_ON_NULL_RETURN(client);
+
+    ewkPage->append(client);
+}
+
+void ewk_page_client_unregister(Ewk_Page* ewkPage, const Ewk_Page_Client* client)
+{
+    EINA_SAFETY_ON_NULL_RETURN(ewkPage);
+    EINA_SAFETY_ON_NULL_RETURN(client);
+
+    ewkPage->remove(client);
+}
diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/efl/ewk_page.h b/Source/WebKit2/WebProcess/InjectedBundle/API/efl/ewk_page.h
new file mode 100644 (file)
index 0000000..1811027
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2015 Ryuan Choi <ryuan.choi@gmail.com>.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @file    ewk_page.h
+ * @brief   Describes the Ewk_Page API.
+ */
+
+#ifndef ewk_page_h
+#define ewk_page_h
+
+#include <Eina.h>
+#include <JavaScriptCore/JSBase.h>
+
+typedef struct EwkPage Ewk_Page;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct EwkPageClient {
+    int version;
+    void *data;
+
+    /**
+     * Callbacks to report load finished.
+     *
+     * @param page page to be finished
+     * @param data data of a page client
+     */
+    void (*load_finished)(Ewk_Page *page, void *data);
+};
+typedef struct EwkPageClient Ewk_Page_Client;
+
+/**
+ * Gets a global JavaScript execution context for the page.
+ *
+ * @param page page to get a global JavaScript execution context
+ *
+ * This function return global JavaScript execution context to extend javascript functionality.
+ */
+EAPI JSGlobalContextRef ewk_page_js_global_context_get(const Ewk_Page *page);
+
+/**
+ * Register a page client which contains several callbacks to the page.
+ *
+ * @param page page to attach page client
+ * @param client page client to add to the page
+ *
+ * This function registers a client, which contains several callbacks receiving events
+ * from WebProcess side, to a @p page.
+ *
+ * @see ewk_page_client_unregister
+ */
+EAPI void ewk_page_client_register(Ewk_Page *page, const Ewk_Page_Client *client);
+
+/**
+ * Unregister a client from the page.
+ *
+ * @param page page to unregister client
+ * @param client page client which contains version, data and callbacks
+ *
+ * @see ewk_page_client_register
+ */
+EAPI void ewk_page_client_unregister(Ewk_Page *page, const Ewk_Page_Client *client);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // ewk_page_h
diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/efl/ewk_page_private.h b/Source/WebKit2/WebProcess/InjectedBundle/API/efl/ewk_page_private.h
new file mode 100644 (file)
index 0000000..1a6ae91
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2015 Ryuan Choi <ryuan.choi@gmail.com>.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ewk_page_private_h
+#define ewk_page_private_h
+
+typedef struct EwkPageClient Ewk_Page_Client;
+
+namespace WebKit {
+class WebPage;
+}
+
+class EwkPage {
+public:
+    explicit EwkPage(WebKit::WebPage*);
+
+    WebKit::WebPage* page() const { return m_page; }
+
+    void append(const Ewk_Page_Client*);
+    void remove(const Ewk_Page_Client*);
+
+private:
+    static void didFinishDocumentLoadForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void *);
+
+    WebKit::WebPage* m_page;
+    Vector<const Ewk_Page_Client*> m_clients;
+};
+
+#endif // ewk_page_private_h
index 2616cdc..69e3b83 100644 (file)
@@ -5,4 +5,4 @@ Name: ewebkit2-extension
 Description: Extension for WebKit2/EFL(ewebkit2)
 Version: @PROJECT_VERSION@
 Requires: eina
-Cflags: -I${includedir}/@WebKit2_OUTPUT_NAME@-@PROJECT_VERSION_MAJOR@/extension
+Cflags: -I${includedir}/@WebKit2_OUTPUT_NAME@-@PROJECT_VERSION_MAJOR@/extension -I${includedir}/@WebKit2_OUTPUT_NAME@-@PROJECT_VERSION_MAJOR@
index 3c02cc7..444a3b3 100644 (file)
@@ -23,6 +23,7 @@ set(WebKit2_OUTPUT_NAME ewebkit2)
 set(CPACK_SOURCE_GENERATOR TBZ2)
 set(GLIB_COMPONENTS gio gobject gthread)
 set(DATA_INSTALL_DIR "share/${WebKit2_OUTPUT_NAME}-${PROJECT_VERSION_MAJOR}" CACHE PATH "Installation path for theme data")
+set(HEADER_INSTALL_DIR "include/${WebKit2_OUTPUT_NAME}-${PROJECT_VERSION_MAJOR}" CACHE PATH "Installation path for header files")
 set(THEME_BINARY_DIR ${CMAKE_BINARY_DIR}/WebCore/platform/efl/DefaultTheme)
 set(WEB_INSPECTOR_DIR "${DATA_INSTALL_DIR}/inspector")
 set(WEBINSPECTORUI_DIR "${CMAKE_SOURCE_DIR}/Source/WebInspectorUI")
@@ -285,4 +286,4 @@ endif ()
 
 if (ENABLE_SUBTLE_CRYPTO)
     find_package(GnuTLS 3.0.0 REQUIRED)
-endif ()
\ No newline at end of file
+endif ()