[GTK] Expose WebKitFrame in WebKit2GTK+ web extensions API
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Aug 2013 08:44:44 +0000 (08:44 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Aug 2013 08:44:44 +0000 (08:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=119743

Reviewed by Anders Carlsson.

Source/WebKit2:

* GNUmakefile.list.am: Add new files to compilation.
* Shared/APIClientTraits.cpp: Update for new interface version.
* Shared/APIClientTraits.h: Ditto.
* UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add WebKitFrame
section.
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new public
symbols.
* UIProcess/API/gtk/docs/webkit2gtk.types: Add
webkit_frame_get_type.
* UIProcess/API/gtk/tests/FrameTest.cpp: Added.
(WebKitFrameTest::create):
(WebKitFrameTest::webPageFromArgs):
(WebKitFrameTest::testMainFrame):
(WebKitFrameTest::testURI):
(WebKitFrameTest::testJavaScriptContext):
(WebKitFrameTest::runTest):
(registerTests):
* UIProcess/API/gtk/tests/GNUmakefile.am: Add new test files.
* UIProcess/API/gtk/tests/TestFrame.cpp: Added.
(webkitFrameTestRun):
(testWebKitFrameMainFrame):
(testWebKitFrameURI):
(testWebKitFrameJavaScriptContext):
(beforeAll):
(afterAll):
* WebProcess/InjectedBundle/API/c/WKBundlePage.h: Add
willDestroyFrame callback to the injected bundle loader client, to
notify the client when a frame is about to be destroyed.
* WebProcess/InjectedBundle/API/gtk/WebKitFrame.cpp: Added.
(webkit_frame_class_init):
(webkitFrameCreate):
(webkit_frame_is_main_frame):
(webkit_frame_get_uri):
(webkit_frame_get_javascript_global_context):
* WebProcess/InjectedBundle/API/gtk/WebKitFrame.h: Added.
* WebProcess/InjectedBundle/API/gtk/WebKitFramePrivate.h: Added.
* WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
(webkitFrameGetOrCreate): Helper function to create a WebKitFrame
wrapping the given WebFrame or returning the wrapper if it already
exists.
(willDestroyFrame): Remove the WebKitFrame wrapping the given
WebFrame if it exists.
(webkitWebPageCreate): Add willDestroyFrame implementation to
injected bundle loader client.
(webkit_web_page_get_main_frame): Return the main frame of the
page.
* WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h:
* WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h:
Include WebKitFrame.h.
* WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:
(WebKit::InjectedBundlePageLoaderClient::willDestroyFrame): New
callback to be called when a frame is about to be destroyed.
* WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h:
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::frameLoaderDestroyed): Call
willDestroyFrame callback of injected bundle loader client.
* WebProcess/qt/QtBuiltinBundlePage.cpp:
(WebKit::QtBuiltinBundlePage::QtBuiltinBundlePage): Add
willDestroyFrame callback.

Tools:

* WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
(WTR::InjectedBundlePage::InjectedBundlePage): Add
willDestroyFrame.

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

23 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/GNUmakefile.list.am
Source/WebKit2/Shared/APIClientTraits.cpp
Source/WebKit2/Shared/APIClientTraits.h
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types
Source/WebKit2/UIProcess/API/gtk/tests/FrameTest.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am
Source/WebKit2/UIProcess/API/gtk/tests/TestFrame.cpp [new file with mode: 0644]
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitFrame.cpp [new file with mode: 0644]
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitFrame.h [new file with mode: 0644]
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitFramePrivate.h [new file with mode: 0644]
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h
Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit2/WebProcess/qt/QtBuiltinBundlePage.cpp
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp

index f5ac012..9968a2d 100644 (file)
@@ -1,3 +1,70 @@
+2013-08-24  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Expose WebKitFrame in WebKit2GTK+ web extensions API
+        https://bugs.webkit.org/show_bug.cgi?id=119743
+
+        Reviewed by Anders Carlsson.
+
+        * GNUmakefile.list.am: Add new files to compilation.
+        * Shared/APIClientTraits.cpp: Update for new interface version.
+        * Shared/APIClientTraits.h: Ditto.
+        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add WebKitFrame
+        section.
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new public
+        symbols.
+        * UIProcess/API/gtk/docs/webkit2gtk.types: Add
+        webkit_frame_get_type.
+        * UIProcess/API/gtk/tests/FrameTest.cpp: Added.
+        (WebKitFrameTest::create):
+        (WebKitFrameTest::webPageFromArgs):
+        (WebKitFrameTest::testMainFrame):
+        (WebKitFrameTest::testURI):
+        (WebKitFrameTest::testJavaScriptContext):
+        (WebKitFrameTest::runTest):
+        (registerTests):
+        * UIProcess/API/gtk/tests/GNUmakefile.am: Add new test files.
+        * UIProcess/API/gtk/tests/TestFrame.cpp: Added.
+        (webkitFrameTestRun):
+        (testWebKitFrameMainFrame):
+        (testWebKitFrameURI):
+        (testWebKitFrameJavaScriptContext):
+        (beforeAll):
+        (afterAll):
+        * WebProcess/InjectedBundle/API/c/WKBundlePage.h: Add
+        willDestroyFrame callback to the injected bundle loader client, to
+        notify the client when a frame is about to be destroyed.
+        * WebProcess/InjectedBundle/API/gtk/WebKitFrame.cpp: Added.
+        (webkit_frame_class_init):
+        (webkitFrameCreate):
+        (webkit_frame_is_main_frame):
+        (webkit_frame_get_uri):
+        (webkit_frame_get_javascript_global_context):
+        * WebProcess/InjectedBundle/API/gtk/WebKitFrame.h: Added.
+        * WebProcess/InjectedBundle/API/gtk/WebKitFramePrivate.h: Added.
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
+        (webkitFrameGetOrCreate): Helper function to create a WebKitFrame
+        wrapping the given WebFrame or returning the wrapper if it already
+        exists.
+        (willDestroyFrame): Remove the WebKitFrame wrapping the given
+        WebFrame if it exists.
+        (webkitWebPageCreate): Add willDestroyFrame implementation to
+        injected bundle loader client.
+        (webkit_web_page_get_main_frame): Return the main frame of the
+        page.
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h:
+        * WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h:
+        Include WebKitFrame.h.
+        * WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:
+        (WebKit::InjectedBundlePageLoaderClient::willDestroyFrame): New
+        callback to be called when a frame is about to be destroyed.
+        * WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h:
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::frameLoaderDestroyed): Call
+        willDestroyFrame callback of injected bundle loader client.
+        * WebProcess/qt/QtBuiltinBundlePage.cpp:
+        (WebKit::QtBuiltinBundlePage::QtBuiltinBundlePage): Add
+        willDestroyFrame callback.
+
 2013-08-24  Antti Koivisto  <antti@apple.com>
 
         Revert accidental change.
index 626ced3..78c34ad 100644 (file)
@@ -138,6 +138,7 @@ webkit2gtk_h_api += \
 
 webkit2_web_extension_h_api += \
        $(WebKit2)/WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.h \
+       $(WebKit2)/WebProcess/InjectedBundle/API/gtk/WebKitFrame.h \
        $(WebKit2)/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h \
        $(WebKit2)/WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h
 
@@ -1059,6 +1060,9 @@ webkit2_sources += \
        Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandlePrivate.h \
        Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.cpp \
        Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.h \
+       Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitFrame.cpp \
+       Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitFrame.h \
+       Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitFramePrivate.h \
        Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.cpp \
        Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.h \
        Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtensionPrivate.h \
index fe68d69..0426164 100644 (file)
@@ -43,6 +43,7 @@ const size_t APIClientTraits<WKBundlePageLoaderClient>::interfaceSizesByVersion[
     offsetof(WKBundlePageLoaderClient, registerIntentServiceForFrame_unavailable),
     offsetof(WKBundlePageLoaderClient, didLayout),
     offsetof(WKBundlePageLoaderClient, featuresUsedInPage),
+    offsetof(WKBundlePageLoaderClient, willLoadDataRequest),
     sizeof(WKBundlePageLoaderClient)
 };
 
index 4622978..df3aabb 100644 (file)
@@ -44,7 +44,7 @@ template<> struct APIClientTraits<WKBundleClient> {
 };
 
 template<> struct APIClientTraits<WKBundlePageLoaderClient> {
-    static const size_t interfaceSizesByVersion[7];
+    static const size_t interfaceSizesByVersion[8];
 };
 
 template<> struct APIClientTraits<WKBundlePageResourceLoadClient> {
index d769e2a..4fa1d27 100644 (file)
@@ -49,6 +49,7 @@
     <title>Web Extensions</title>
     <xi:include href="xml/WebKitWebExtension.xml"/>
     <xi:include href="xml/WebKitWebPage.xml"/>
+    <xi:include href="xml/WebKitFrame.xml"/>
   </chapter>
 
   <index id="index-all">
index 2704d63..29078dd 100644 (file)
@@ -1040,6 +1040,7 @@ WebKitWebPage
 webkit_web_page_get_dom_document
 webkit_web_page_get_id
 webkit_web_page_get_uri
+webkit_web_page_get_main_frame
 
 <SUBSECTION Standard>
 WebKitWebPageClass
@@ -1054,3 +1055,24 @@ WEBKIT_WEB_PAGE_GET_CLASS
 WebKitWebPagePrivate
 webkit_web_page_get_type
 </SECTION>
+
+<SECTION>
+<FILE>WebKitFrame</FILE>
+WebKitFrame
+webkit_frame_is_main_frame
+webkit_frame_get_uri
+webkit_frame_get_javascript_global_context
+
+<SUBSECTION Standard>
+WebKitFrameClass
+WEBKIT_TYPE_FRAME
+WEBKIT_FRAME
+WEBKIT_IS_FRAME
+WEBKIT_FRAME_CLASS
+WEBKIT_IS_FRAME_CLASS
+WEBKIT_FRAME_GET_CLASS
+
+<SUBSECTION Private>
+WebKitFramePrivate
+webkit_frame_get_type
+</SECTION>
index ab620f0..5b1ea3c 100644 (file)
@@ -25,4 +25,5 @@ webkit_web_view_group_get_type
 webkit_web_extension_get_type
 webkit_web_page_get_type
 webkit_authentication_request_get_type
-webkit_credential_get_type
\ No newline at end of file
+webkit_credential_get_type
+webkit_frame_get_type
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/FrameTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/FrameTest.cpp
new file mode 100644 (file)
index 0000000..4d4850f
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2013 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include "WebProcessTest.h"
+#include <gio/gio.h>
+#include <webkit2/webkit-web-extension.h>
+
+class WebKitFrameTest : public WebProcessTest {
+public:
+    static PassOwnPtr<WebProcessTest> create() { return adoptPtr(new WebKitFrameTest()); }
+
+private:
+    guint64 webPageFromArgs(GVariant* args)
+    {
+        GVariantIter iter;
+        g_variant_iter_init(&iter, args);
+
+        const char* key;
+        GVariant* value;
+        while (g_variant_iter_loop(&iter, "{&sv}", &key, &value)) {
+            if (!strcmp(key, "pageID") && g_variant_classify(value) == G_VARIANT_CLASS_UINT64)
+                return g_variant_get_uint64(value);
+        }
+
+        g_assert_not_reached();
+        return 0;
+    }
+
+    bool testMainFrame(WebKitWebExtension* extension, GVariant* args)
+    {
+        WebKitWebPage* page = webkit_web_extension_get_page(extension, webPageFromArgs(args));
+        g_assert(WEBKIT_IS_WEB_PAGE(page));
+
+        WebKitFrame* frame = webkit_web_page_get_main_frame(page);
+        g_assert(WEBKIT_IS_FRAME(frame));
+        g_assert(webkit_frame_is_main_frame(frame));
+
+        return true;
+    }
+
+    bool testURI(WebKitWebExtension* extension, GVariant* args)
+    {
+        WebKitWebPage* page = webkit_web_extension_get_page(extension, webPageFromArgs(args));
+        g_assert(WEBKIT_IS_WEB_PAGE(page));
+
+        WebKitFrame* frame = webkit_web_page_get_main_frame(page);
+        g_assert(WEBKIT_IS_FRAME(frame));
+        g_assert_cmpstr(webkit_web_page_get_uri(page), ==, webkit_frame_get_uri(frame));
+
+        return true;
+    }
+
+    bool testJavaScriptContext(WebKitWebExtension* extension, GVariant* args)
+    {
+        WebKitWebPage* page = webkit_web_extension_get_page(extension, webPageFromArgs(args));
+        g_assert(WEBKIT_IS_WEB_PAGE(page));
+
+        WebKitFrame* frame = webkit_web_page_get_main_frame(page);
+        g_assert(WEBKIT_IS_FRAME(frame));
+        g_assert(webkit_frame_get_javascript_global_context(frame));
+
+        return true;
+    }
+
+    virtual bool runTest(const char* testName, WebKitWebExtension* extension, GVariant* args)
+    {
+        if (!strcmp(testName, "main-frame"))
+            return testMainFrame(extension, args);
+        if (!strcmp(testName, "uri"))
+            return testURI(extension, args);
+        if (!strcmp(testName, "javascript-context"))
+            return testJavaScriptContext(extension, args);
+
+        g_assert_not_reached();
+        return false;
+    }
+};
+
+static void __attribute__((constructor)) registerTests()
+{
+    REGISTER_TEST(WebKitFrameTest, "WebKitFrame/main-frame");
+    REGISTER_TEST(WebKitFrameTest, "WebKitFrame/uri");
+    REGISTER_TEST(WebKitFrameTest, "WebKitFrame/javascript-context");
+}
index ff2d534..abda0ea 100644 (file)
@@ -7,6 +7,7 @@ TEST_PROGS += \
        Programs/WebKit2APITests/TestCookieManager \
        Programs/WebKit2APITests/TestDOMNode \
        Programs/WebKit2APITests/TestDownloads \
+       Programs/WebKit2APITests/TestFrame \
        Programs/WebKit2APITests/TestInspector \
        Programs/WebKit2APITests/TestInspectorServer \
        Programs/WebKit2APITests/TestLoaderClient \
@@ -126,6 +127,7 @@ Libraries_WebExtensions_libWebExtensionTest_la_CFLAGS = \
 noinst_LTLIBRARIES += Libraries/WebExtensions/libWebProcessTest.la
 Libraries_WebExtensions_libWebProcessTest_la_SOURCES = \
        Source/WebKit2/UIProcess/API/gtk/tests/DOMNodeTest.cpp \
+       Source/WebKit2/UIProcess/API/gtk/tests/FrameTest.cpp \
        Source/WebKit2/UIProcess/API/gtk/tests/WebProcessTest.cpp \
        Source/WebKit2/UIProcess/API/gtk/tests/WebProcessTest.h
 
@@ -303,4 +305,10 @@ Programs_WebKit2APITests_TestDOMNode_CPPFLAGS = $(webkit2_tests_cppflags)
 Programs_WebKit2APITests_TestDOMNode_LDADD = $(webkit2_tests_ldadd)
 Programs_WebKit2APITests_TestDOMNode_LDFLAGS = $(webkit2_tests_ldflags)
 
+Programs_WebKit2APITests_TestFrame_SOURCES = \
+        Source/WebKit2/UIProcess/API/gtk/tests/TestFrame.cpp
+Programs_WebKit2APITests_TestFrame_CPPFLAGS = $(webkit2_tests_cppflags)
+Programs_WebKit2APITests_TestFrame_LDADD = $(webkit2_tests_ldadd)
+Programs_WebKit2APITests_TestFrame_LDFLAGS = $(webkit2_tests_ldflags)
+
 endif # ENABLE_WEBKIT2
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestFrame.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestFrame.cpp
new file mode 100644 (file)
index 0000000..a63b079
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2013 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2,1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include "WebProcessTestRunner.h"
+#include "WebViewTest.h"
+#include <gtk/gtk.h>
+#include <webkit2/webkit2.h>
+
+static WebProcessTestRunner* testRunner;
+
+static void webkitFrameTestRun(WebViewTest* test, const char* testName)
+{
+    static const char* testHTML = "<html><body></body></html>";
+    test->loadHtml(testHTML, 0);
+    test->waitUntilLoadFinished();
+
+    GVariantBuilder builder;
+    g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
+    g_variant_builder_add(&builder, "{sv}", "pageID", g_variant_new_uint64(webkit_web_view_get_page_id(test->m_webView)));
+    g_assert(testRunner->runTest("WebKitFrame", testName, g_variant_builder_end(&builder)));
+}
+
+static void testWebKitFrameMainFrame(WebViewTest* test, gconstpointer)
+{
+    webkitFrameTestRun(test, "main-frame");
+}
+
+static void testWebKitFrameURI(WebViewTest* test, gconstpointer)
+{
+    webkitFrameTestRun(test, "uri");
+}
+
+static void testWebKitFrameJavaScriptContext(WebViewTest* test, gconstpointer)
+{
+    webkitFrameTestRun(test, "javascript-context");
+}
+
+void beforeAll()
+{
+    testRunner = new WebProcessTestRunner();
+    webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), WEBKIT_TEST_WEB_EXTENSIONS_DIR);
+
+    WebViewTest::add("WebKitFrame", "main-frame", testWebKitFrameMainFrame);
+    WebViewTest::add("WebKitFrame", "uri", testWebKitFrameURI);
+    WebViewTest::add("WebKitFrame", "javascript-context", testWebKitFrameJavaScriptContext);
+}
+
+void afterAll()
+{
+    delete testRunner;
+}
index a7bc6df..655a222 100644 (file)
@@ -112,6 +112,7 @@ typedef void (*WKBundlePageDidLayoutCallback)(WKBundlePageRef page, WKLayoutMile
 typedef void (*WKBundlePageFeaturesUsedInPageCallback)(WKBundlePageRef page, WKArrayRef featureStrings, const void *clientInfo);
 typedef void (*WKBundlePageWillLoadURLRequestCallback)(WKBundlePageRef page, WKURLRequestRef request, WKTypeRef userData, const void *clientInfo);
 typedef void (*WKBundlePageWillLoadDataRequestCallback)(WKBundlePageRef page, WKURLRequestRef request, WKDataRef data, WKStringRef MIMEType, WKStringRef encodingName, WKURLRef unreachableURL, WKTypeRef userData, const void *clientInfo);
+typedef void (*WKBundlePageWillDestroyFrame)(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo);
 
 struct WKBundlePageLoaderClient {
     int                                                                     version;
@@ -164,10 +165,13 @@ struct WKBundlePageLoaderClient {
     // Version 6
     WKBundlePageWillLoadURLRequestCallback                                  willLoadURLRequest;
     WKBundlePageWillLoadDataRequestCallback                                 willLoadDataRequest;
+
+    // Version 7
+    WKBundlePageWillDestroyFrame                                            willDestroyFrame;
 };
 typedef struct WKBundlePageLoaderClient WKBundlePageLoaderClient;
 
-enum { kWKBundlePageLoaderClientCurrentVersion = 6 };
+enum { kWKBundlePageLoaderClientCurrentVersion = 7 };
 
 enum {
     WKBundlePagePolicyActionPassThrough,
diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitFrame.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitFrame.cpp
new file mode 100644 (file)
index 0000000..a8b21f7
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2013 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2,1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebKitFrame.h"
+
+#include "WebKitFramePrivate.h"
+#include "WebKitPrivate.h"
+#include <wtf/text/CString.h>
+
+using namespace WebKit;
+using namespace WebCore;
+
+struct _WebKitFramePrivate {
+    RefPtr<WebFrame> webFrame;
+
+    CString uri;
+};
+
+WEBKIT_DEFINE_TYPE(WebKitFrame, webkit_frame, G_TYPE_OBJECT)
+
+static void webkit_frame_class_init(WebKitFrameClass* klass)
+{
+}
+
+WebKitFrame* webkitFrameCreate(WebFrame* webFrame)
+{
+    WebKitFrame* frame = WEBKIT_FRAME(g_object_new(WEBKIT_TYPE_FRAME, NULL));
+    frame->priv->webFrame = webFrame;
+    return frame;
+}
+
+/**
+ * webkit_frame_is_main_frame:
+ * @frame: a #WebKitFrame
+ *
+ * Gets whether @frame is the a main frame of a #WebKitWebPage
+ *
+ * Returns: %TRUE if @frame is a main frame or %FALSE otherwise
+ *
+ * Since: 2.2
+ */
+gboolean webkit_frame_is_main_frame(WebKitFrame* frame)
+{
+    g_return_val_if_fail(WEBKIT_IS_FRAME(frame), FALSE);
+
+    return frame->priv->webFrame->isMainFrame();
+}
+
+/**
+ * webkit_frame_get_uri:
+ * @frame: a #WebKitFrame
+ *
+ * Gets the current active URI of @frame.
+ *
+ * Returns: the current active URI of @frame or %NULL if nothing has been
+ *    loaded yet.
+ *
+ * Since: 2.2
+ */
+const gchar* webkit_frame_get_uri(WebKitFrame* frame)
+{
+    g_return_val_if_fail(WEBKIT_IS_FRAME(frame), 0);
+
+    if (frame->priv->uri.isNull())
+        frame->priv->uri = frame->priv->webFrame->url().utf8();
+
+    return frame->priv->uri.data();
+}
+
+/**
+ * webkit_frame_get_javascript_global_context:
+ * @frame: a #WebKitFrame
+ *
+ * Gets the global JavaScript execution context. Use this function to bridge
+ * between the WebKit and JavaScriptCore APIs.
+ *
+ * Returns: (transfer none): the global JavaScript context of @frame
+ *
+ * Since: 2.2
+ */
+JSGlobalContextRef webkit_frame_get_javascript_global_context(WebKitFrame* frame)
+{
+    g_return_val_if_fail(WEBKIT_IS_FRAME(frame), 0);
+
+    return frame->priv->webFrame->jsContext();
+}
diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitFrame.h b/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitFrame.h
new file mode 100644 (file)
index 0000000..e345c5c
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2013 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2,1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#if !defined(__WEBKIT_WEB_EXTENSION_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <webkit2/webkit-web-extension.h> can be included directly."
+#endif
+
+#ifndef WebKitFrame_h
+#define WebKitFrame_h
+
+#include <JavaScriptCore/JSBase.h>
+#include <glib-object.h>
+#include <webkit2/WebKitDefines.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_FRAME            (webkit_frame_get_type())
+#define WEBKIT_FRAME(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_FRAME, WebKitFrame))
+#define WEBKIT_IS_FRAME(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_FRAME))
+#define WEBKIT_FRAME_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_FRAME, WebKitFrameClass))
+#define WEBKIT_IS_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_FRAME))
+#define WEBKIT_FRAME_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_FRAME, WebKitFrameClass))
+
+typedef struct _WebKitFrame        WebKitFrame;
+typedef struct _WebKitFrameClass   WebKitFrameClass;
+typedef struct _WebKitFramePrivate WebKitFramePrivate;
+
+struct _WebKitFrame {
+    GObject parent;
+
+    WebKitFramePrivate *priv;
+};
+
+struct _WebKitFrameClass {
+    GObjectClass parent_class;
+};
+
+WEBKIT_API GType
+webkit_frame_get_type                      (void);
+
+WEBKIT_API gboolean
+webkit_frame_is_main_frame                 (WebKitFrame *frame);
+
+WEBKIT_API const gchar *
+webkit_frame_get_uri                       (WebKitFrame *frame);
+
+WEBKIT_API JSGlobalContextRef
+webkit_frame_get_javascript_global_context (WebKitFrame *frame);
+
+G_END_DECLS
+
+#endif
diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitFramePrivate.h b/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitFramePrivate.h
new file mode 100644 (file)
index 0000000..3c7fab4
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2013 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebKitFramePrivate_h
+#define WebKitFramePrivate_h
+
+#include "WebFrame.h"
+#include "WebKitFrame.h"
+
+WebKitFrame* webkitFrameCreate(WebKit::WebFrame*);
+
+#endif // WebKitFramePrivate_h
index 12d623e..dbec2c3 100644 (file)
@@ -25,9 +25,9 @@
 #include "InjectedBundle.h"
 #include "WKBundleAPICast.h"
 #include "WKBundleFrame.h"
-#include "WebFrame.h"
 #include "WebImage.h"
 #include "WebKitDOMDocumentPrivate.h"
+#include "WebKitFramePrivate.h"
 #include "WebKitMarshal.h"
 #include "WebKitPrivate.h"
 #include "WebKitURIRequestPrivate.h"
@@ -39,6 +39,7 @@
 #include <WebCore/Frame.h>
 #include <WebCore/FrameView.h>
 #include <glib/gi18n-lib.h>
+#include <wtf/NeverDestroyed.h>
 #include <wtf/text/CString.h>
 
 using namespace WebKit;
@@ -67,6 +68,26 @@ static guint signals[LAST_SIGNAL] = { 0, };
 
 WEBKIT_DEFINE_TYPE(WebKitWebPage, webkit_web_page, G_TYPE_OBJECT)
 
+typedef HashMap<WebFrame*, GRefPtr<WebKitFrame>> WebFrameMap;
+
+static WebFrameMap& webFrameMap()
+{
+    static NeverDestroyed<WebFrameMap> map;
+    return map;
+}
+
+static WebKitFrame* webkitFrameGetOrCreate(WebFrame* webFrame)
+{
+    GRefPtr<WebKitFrame> frame = webFrameMap().get(webFrame);
+    if (frame)
+        return frame.get();
+
+    frame = adoptGRef(webkitFrameCreate(webFrame));
+    webFrameMap().set(webFrame, frame);
+
+    return frame.get();
+}
+
 static CString getProvisionalURLForFrame(WebFrame* webFrame)
 {
     DocumentLoader* documentLoader = webFrame->coreFrame()->loader().provisionalDocumentLoader();
@@ -117,6 +138,11 @@ static void didFinishDocumentLoadForFrame(WKBundlePageRef, WKBundleFrameRef fram
     g_signal_emit(WEBKIT_WEB_PAGE(clientInfo), signals[DOCUMENT_LOADED], 0);
 }
 
+static void willDestroyFrame(WKBundlePageRef, WKBundleFrameRef frame, const void *clientInfo)
+{
+    webFrameMap().remove(toImpl(frame));
+}
+
 static void didInitiateLoadForResource(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, WKURLRequestRef request, bool pageLoadIsProvisional, const void*)
 {
     ImmutableDictionary::MapType message;
@@ -311,8 +337,9 @@ WebKitWebPage* webkitWebPageCreate(WebPage* webPage)
         0, // registerIntentServiceForFrame_unavailable
         0, // didLayout
         0, // featuresUsedInPage
-        0, // willLoadURLRequest;
-        0, // willLoadDataRequest;
+        0, // willLoadURLRequest
+        0, // willLoadDataRequest
+        willDestroyFrame
     };
     WKBundlePageSetPageLoaderClient(toAPI(webPage), &loaderClient);
 
@@ -420,3 +447,10 @@ const gchar* webkit_web_page_get_uri(WebKitWebPage* webPage)
 
     return webPage->priv->uri.data();
 }
+
+WebKitFrame* webkit_web_page_get_main_frame(WebKitWebPage* webPage)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEB_PAGE(webPage), 0);
+
+    return webkitFrameGetOrCreate(webPage->priv->webPage->mainWebFrame());
+}
index ff6e00d..3745528 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <glib-object.h>
 #include <webkit2/WebKitDefines.h>
+#include <webkit2/WebKitFrame.h>
 #include <webkitdom/webkitdom.h>
 
 G_BEGIN_DECLS
@@ -61,7 +62,10 @@ WEBKIT_API guint64
 webkit_web_page_get_id           (WebKitWebPage *web_page);
 
 WEBKIT_API const gchar *
-webkit_web_page_get_uri (WebKitWebPage *web_page);
+webkit_web_page_get_uri          (WebKitWebPage *web_page);
+
+WEBKIT_API WebKitFrame *
+webkit_web_page_get_main_frame   (WebKitWebPage *web_page);
 
 G_END_DECLS
 
index ffbb557..1de975a 100644 (file)
@@ -22,6 +22,7 @@
 
 #define __WEBKIT_WEB_EXTENSION_H_INSIDE__
 
+#include <webkit2/WebKitFrame.h>
 #include <webkit2/WebKitURIRequest.h>
 #include <webkit2/WebKitURIResponse.h>
 #include <webkit2/WebKitWebExtension.h>
index 95f6c00..1f80b20 100644 (file)
@@ -352,4 +352,12 @@ void InjectedBundlePageLoaderClient::featuresUsedInPage(WebPage* page, const Vec
     return m_client.featuresUsedInPage(toAPI(page), toAPI(featureStringObjectsArray.get()), m_client.clientInfo);
 }
 
+void InjectedBundlePageLoaderClient::willDestroyFrame(WebPage* page, WebFrame* frame)
+{
+    if (!m_client.willDestroyFrame)
+        return;
+
+    m_client.willDestroyFrame(toAPI(page), toAPI(frame), m_client.clientInfo);
+}
+
 } // namespace WebKit
index c89db59..682aaee 100644 (file)
@@ -90,6 +90,8 @@ public:
     bool shouldForceUniversalAccessFromLocalURL(WebPage*, const String& url);
 
     void featuresUsedInPage(WebPage*, const Vector<String>&);
+
+    void willDestroyFrame(WebPage*, WebFrame*);
 };
 
 } // namespace WebKit
index f2d3f35..44f51f1 100644 (file)
@@ -95,6 +95,9 @@ WebFrameLoaderClient::~WebFrameLoaderClient()
     
 void WebFrameLoaderClient::frameLoaderDestroyed()
 {
+    if (WebPage* webPage = m_frame->page())
+        webPage->injectedBundleLoaderClient().willDestroyFrame(webPage, m_frame);
+
     m_frame->invalidate();
 
     // Balances explicit ref() in WebFrame::createMainFrame and WebFrame::createSubframe.
index b32fedf..f76c036 100644 (file)
@@ -82,6 +82,7 @@ QtBuiltinBundlePage::QtBuiltinBundlePage(QtBuiltinBundle* bundle, WKBundlePageRe
         0, // featuresUsedInPage
         0, // willLoadURLRequest
         0, // willLoadDataRequest
+        0, // willDestroyFrame
     };
     WKBundlePageSetPageLoaderClient(m_page, &loaderClient);
 }
index 9aed724..3b141ed 100644 (file)
@@ -1,3 +1,14 @@
+2013-08-24  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Expose WebKitFrame in WebKit2GTK+ web extensions API
+        https://bugs.webkit.org/show_bug.cgi?id=119743
+
+        Reviewed by Anders Carlsson.
+
+        * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
+        (WTR::InjectedBundlePage::InjectedBundlePage): Add
+        willDestroyFrame.
+
 2013-08-23  Thiago de Barros Lacerda  <thiago.lacerda@openbossa.org>
 
         Move TestWebKitAPI_LIBRARIES before platform specific cmake include
index b1dbab8..d7bad77 100644 (file)
@@ -309,6 +309,7 @@ InjectedBundlePage::InjectedBundlePage(WKBundlePageRef page)
         0, // featuresUsedInPage
         0, // willLoadURLRequest
         0, // willLoadDataRequest
+        0, // willDestroyFrame
     };
     WKBundlePageSetPageLoaderClient(m_page, &loaderClient);