Commit 51f44d80 authored by carlosgc@webkit.org's avatar carlosgc@webkit.org

[GTK] Expose WebKitFrame in WebKit2GTK+ web extensions API

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: http://svn.webkit.org/repository/webkit/trunk@154540 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 200ae688
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.
......
......@@ -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 \
......
......@@ -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)
};
......
......@@ -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> {
......
......@@ -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">
......
......@@ -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>
......@@ -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
/*
* 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");
}
......@@ -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
/*
* 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;
}
......@@ -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,
......
/*
* 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();
}
/*
* 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
/*
* 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
......@@ -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)