Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 4 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
View
2 lib/gwebkitjs/CMakeLists.txt
@@ -18,6 +18,7 @@ set(GWEBKITJS_SOURCES
gwebkitjs_value.c
gwebkitjs_base.c
gwebkitjs_util.c
+ gwebkitjs_helper.c
)
set(GWEBKITJS_HEADERS
@@ -26,6 +27,7 @@ set(GWEBKITJS_HEADERS
gwebkitjs_value.h
gwebkitjs_base.h
gwebkitjs_util.h
+ gwebkitjs_helper.h
)
add_library(gwebkitjs SHARED ${GWEBKITJS_SOURCES})
View
21 lib/gwebkitjs/gwebkitjs_base.c
@@ -45,6 +45,7 @@ static void gwebkitjs_base_finalize(GObject *obj);
static GWebKitJSClosureType clsr_type_v_p_p = NULL;
static gboolean gwebkitjs_base_is_valid_name(const gchar *name);
+static JSClassRef gwebkitjs_base_get_jsclass(GWebKitJSBaseClass *klass);
/**
* GWebKitJSBaseClass::has_property:
@@ -248,7 +249,7 @@ gwebkitjs_base_finalize_cb(JSObjectRef jsobj)
JSObjectSetPrivate(jsobj, NULL);
}
-bool
+static bool
gwebkitjs_base_has_property_cb(JSContextRef jsctx, JSObjectRef jsobj,
JSStringRef jsname)
{
@@ -275,7 +276,7 @@ gwebkitjs_base_has_property_cb(JSContextRef jsctx, JSObjectRef jsobj,
return res;
}
-JSValueRef
+static JSValueRef
gwebkitjs_base_get_property_cb(JSContextRef jsctx, JSObjectRef jsobj,
JSStringRef jsname, JSValueRef *jserr)
{
@@ -321,7 +322,7 @@ gwebkitjs_base_get_property_cb(JSContextRef jsctx, JSObjectRef jsobj,
return NULL;
}
-bool
+static bool
gwebkitjs_base_set_property_cb(JSContextRef jsctx, JSObjectRef jsobj,
JSStringRef jsname, JSValueRef jsvalue,
JSValueRef *jserr)
@@ -365,7 +366,7 @@ gwebkitjs_base_set_property_cb(JSContextRef jsctx, JSObjectRef jsobj,
return res;
}
-bool
+static bool
gwebkitjs_base_delete_property_cb(JSContextRef jsctx, JSObjectRef jsobj,
JSStringRef jsname, JSValueRef *jserr)
{
@@ -402,7 +403,7 @@ gwebkitjs_base_delete_property_cb(JSContextRef jsctx, JSObjectRef jsobj,
return res;
}
-void
+static void
gwebkitjs_base_get_property_names_cb(JSContextRef jsctx, JSObjectRef jsobj,
JSPropertyNameAccumulatorRef jsnames)
{
@@ -434,7 +435,7 @@ gwebkitjs_base_get_property_names_cb(JSContextRef jsctx, JSObjectRef jsobj,
g_object_unref(ctx);
}
-JSValueRef
+static JSValueRef
gwebkitjs_base_call_function_cb(JSContextRef jsctx, JSObjectRef jsobj,
JSObjectRef jsthis, size_t argc,
const JSValueRef *jsargv, JSValueRef *jserr)
@@ -491,7 +492,7 @@ gwebkitjs_base_call_function_cb(JSContextRef jsctx, JSObjectRef jsobj,
return jsres;
}
-JSObjectRef
+static JSObjectRef
gwebkitjs_base_call_construct_cb(JSContextRef jsctx, JSObjectRef jsobj,
size_t argc, const JSValueRef *jsargv,
JSValueRef *jserr)
@@ -543,7 +544,7 @@ gwebkitjs_base_call_construct_cb(JSContextRef jsctx, JSObjectRef jsobj,
return NULL;
}
-bool
+static bool
gwebkitjs_base_has_instance_cb(JSContextRef jsctx, JSObjectRef jsobj,
JSValueRef jsins, JSValueRef *jserr)
{
@@ -584,7 +585,7 @@ gwebkitjs_base_has_instance_cb(JSContextRef jsctx, JSObjectRef jsobj,
return res;
}
-JSValueRef
+static JSValueRef
gwebkitjs_base_convert_to_cb(JSContextRef jsctx, JSObjectRef jsobj,
JSType type, JSValueRef *jserr)
{
@@ -676,7 +677,7 @@ gwebkitjs_base_get_definition(GWebKitJSBaseClass *klass)
*
* Return Value:
**/
-JSClassRef
+static JSClassRef
gwebkitjs_base_get_jsclass(GWebKitJSBaseClass *klass)
{
JSClassDefinition *define;
View
1 lib/gwebkitjs/gwebkitjs_base.h
@@ -85,7 +85,6 @@ struct _GWebKitJSBaseClass {
extern "C" {
#endif
GType gwebkitjs_base_get_type();
- JSClassRef gwebkitjs_base_get_jsclass(GWebKitJSBaseClass *klass);
JSClassRef gwebkitjs_base_get_jsclass_from_type(GType type);
void gwebkitjs_base_set_name(GType type, const gchar *name);
GWebKitJSValue *gwebkitjs_base_new(GWebKitJSContext *ctx, GType type);
View
5 lib/gwebkitjs/gwebkitjs_context.c
@@ -333,11 +333,8 @@ gwebkitjs_context_new(GType global)
JSClassRef globalclass;
JSGlobalContextRef jsctx;
GWebKitJSContext *res;
- GWebKitJSBaseClass *baseklass;
- baseklass = g_type_class_ref(global);
- globalclass = gwebkitjs_base_get_jsclass(baseklass);
- g_type_class_unref(baseklass);
+ globalclass = gwebkitjs_base_get_jsclass_from_type(global);
jsctx = JSGlobalContextCreate(globalclass);
res = gwebkitjs_context_new_from_context(jsctx);
View
158 lib/gwebkitjs/gwebkitjs_helper.c
@@ -0,0 +1,158 @@
+#include <webkit/webkitwebview.h>
+#include <gwebkitjs_helper.h>
+#include <gwebkitjs_context.h>
+#include <gwebkitjs_value.h>
+
+/***************************************************************************
+ * Copyright (C) 2012~2012 by Yichao Yu *
+ * yyc1992@gmail.com *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+
+struct _GWebKitJSHelperPrivate {
+ WebKitWebView *webview;
+ gulong win_obj_clear_id;
+};
+
+static void gwebkitjs_helper_init(GWebKitJSHelper *self,
+ GWebKitJSHelperClass *klass);
+static void gwebkitjs_helper_class_init(GWebKitJSHelperClass *klass,
+ gpointer data);
+static void gwebkitjs_helper_dispose(GObject *obj);
+static void gwebkitjs_helper_finalize(GObject *obj);
+
+enum {
+ SIGNAL_WINDOW_OBJECT_CLEARED,
+ _SIGNAL_LAST
+};
+
+static guint signals[_SIGNAL_LAST] = {0};
+
+GType
+gwebkitjs_helper_get_type()
+{
+ static GType helper_type = 0;
+ if (G_UNLIKELY(helper_type == 0)) {
+ const GTypeInfo helper_info = {
+ .class_size = sizeof(GWebKitJSHelperClass),
+ .base_init = NULL,
+ .base_finalize = NULL,
+ .class_init = (GClassInitFunc)gwebkitjs_helper_class_init,
+ .class_finalize = NULL,
+ .class_data = NULL,
+ .instance_size = sizeof(GWebKitJSHelper),
+ .n_preallocs = 0,
+ .instance_init = (GInstanceInitFunc)gwebkitjs_helper_init,
+ .value_table = NULL,
+ };
+
+ helper_type = g_type_register_static(G_TYPE_OBJECT, "GWebKitJSHelper",
+ &helper_info, 0);
+ }
+ return helper_type;
+}
+
+static void
+gwebkitjs_helper_init(GWebKitJSHelper *self, GWebKitJSHelperClass *klass)
+{
+ GWebKitJSHelperPrivate *priv;
+ priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self,
+ GWEBKITJS_TYPE_HELPER,
+ GWebKitJSHelperPrivate);
+ priv->webview = NULL;
+ priv->win_obj_clear_id = 0;
+}
+
+static void
+gwebkitjs_helper_class_init(GWebKitJSHelperClass *klass, gpointer data)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+ g_type_class_add_private(klass, sizeof(GWebKitJSHelperPrivate));
+ gobject_class->dispose = gwebkitjs_helper_dispose;
+ gobject_class->finalize = gwebkitjs_helper_finalize;
+ /**
+ * GWebKitJSHelper::window-object-cleared:
+ * @helper: (transfer none) (allow-none):
+ * @frame: (transfer none) (allow-none):
+ * @ctx: (transfer none) (allow-none):
+ * @win_obj: (transfer none) (allow-none):
+ **/
+ signals[SIGNAL_WINDOW_OBJECT_CLEARED] =
+ g_signal_new("window-object-cleared", GWEBKITJS_TYPE_HELPER,
+ G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 3,
+ WEBKIT_TYPE_WEB_FRAME, GWEBKITJS_TYPE_CONTEXT,
+ GWEBKITJS_TYPE_VALUE);
+}
+
+static void
+gwebkitjs_helper_dispose(GObject *obj)
+{
+ GWebKitJSHelper *self = GWEBKITJS_HELPER(obj);
+ if (self->priv->webview) {
+ if (self->priv->win_obj_clear_id) {
+ g_signal_handler_disconnect(self->priv->webview,
+ self->priv->win_obj_clear_id);
+ self->priv->win_obj_clear_id = 0;
+ }
+ g_object_unref(self->priv->webview);
+ self->priv->webview = NULL;
+ }
+}
+
+static void
+gwebkitjs_helper_finalize(GObject *obj)
+{
+ /* GWebKitJSHelper *self = GWEBKITJS_HELPER(obj); */
+}
+
+static void
+gwebkitjs_helper_window_object_cleared_cb(WebKitWebView *webview,
+ WebKitWebFrame *frame,
+ JSGlobalContextRef jsctx,
+ JSObjectRef jsobj,
+ GWebKitJSHelper *self)
+{
+ GWebKitJSContext *ctx;
+ GWebKitJSValue *value;
+ ctx = gwebkitjs_context_new_from_context(jsctx);
+ gwj_return_if_false(ctx);
+ value = gwebkitjs_value_new(GWEBKITJS_TYPE_VALUE, ctx, jsobj);
+ if (G_UNLIKELY(!value)) {
+ g_object_unref(ctx);
+ return;
+ }
+ g_signal_emit(self, signals[SIGNAL_WINDOW_OBJECT_CLEARED], 0,
+ frame, ctx, value);
+}
+
+/**
+ * gwebkitjs_helper_new:
+ * webview: (allow-none) (transfer none):
+ *
+ * Returns: (allow-none) (transfer full):
+ **/
+GWebKitJSHelper*
+gwebkitjs_helper_new(WebKitWebView *webview)
+{
+ GWebKitJSHelper *self;
+ gwj_return_val_if_false(WEBKIT_IS_WEB_VIEW(webview), NULL);
+ self = g_object_new(GWEBKITJS_TYPE_HELPER, NULL);
+ self->priv->webview = g_object_ref(webview);
+ self->priv->win_obj_clear_id = g_signal_connect(
+ webview, "window-object-cleared",
+ G_CALLBACK(gwebkitjs_helper_window_object_cleared_cb), self);
+ printf("connection id: %lu\n", self->priv->win_obj_clear_id);
+ return self;
+}
View
59 lib/gwebkitjs/gwebkitjs_helper.h
@@ -0,0 +1,59 @@
+#ifndef __GWEBKITJS_HELPER_H__
+#define __GWEBKITJS_HELPER_H__
+
+/***************************************************************************
+ * Copyright (C) 2012~2012 by Yichao Yu *
+ * yyc1992@gmail.com *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+
+#define GWEBKITJS_TYPE_HELPER (gwebkitjs_helper_get_type())
+#define GWEBKITJS_HELPER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), GWEBKITJS_TYPE_HELPER, \
+ GWebKitJSHelper))
+#define GWEBKITJS_IS_HELPER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), GWEBKITJS_TYPE_HELPER))
+#define GWEBKITJS_HELPER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), GWEBKITJS_TYPE_HELPER, \
+ GWebKitJSHelperClass))
+#define GWEBKITJS_IS_HELPER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), GWEBKITJS_TYPE_HELPER))
+#define GWEBKITJS_HELPER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), GWEBKITJS_TYPE_HELPER, \
+ GWebKitJSHelperClass))
+
+typedef struct _GWebKitJSHelper GWebKitJSHelper;
+typedef struct _GWebKitJSHelperPrivate GWebKitJSHelperPrivate;
+typedef struct _GWebKitJSHelperClass GWebKitJSHelperClass;
+
+struct _GWebKitJSHelper {
+ GObject parent;
+ GWebKitJSHelperPrivate *priv;
+};
+
+struct _GWebKitJSHelperClass {
+ GObjectClass parent_class;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ GType gwebkitjs_helper_get_type();
+ GWebKitJSHelper *gwebkitjs_helper_new(WebKitWebView *webview);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __GWEBKITJS_HELPER_H__ */
View
6 lib/gwebkitjs/test/CMakeLists.txt
@@ -19,3 +19,9 @@ add_test(NAME jsbase
COMMAND env GI_TYPELIB_PATH=${CMAKE_CURRENT_BINARY_DIR}/..
LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/..
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_jsbase.py)
+
+add_test(NAME helper
+ COMMAND env GI_TYPELIB_PATH=${CMAKE_CURRENT_BINARY_DIR}/..
+ LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/..
+ ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_helper.py
+ ${CMAKE_CURRENT_SOURCE_DIR}/helper.html)
View
9 lib/gwebkitjs/test/helper.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <script src="helper.js"></script>
+ </head>
+ <body>
+ </body>
+</html>
View
2 lib/gwebkitjs/test/helper.js
@@ -0,0 +1,2 @@
+console.log(window);
+console.log(window.pyobj)
View
29 lib/gwebkitjs/test/test_helper.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+from gi.repository import Gtk, GWebKitJS, WebKit, GLib
+import os, sys
+
+def win_obj_clr_cb(helper, frame, ctx, obj):
+ print(helper, frame, ctx, obj)
+ ctx.set_property(obj, "pyobj", ctx.make_string("this is a py str"), 0)
+
+def load_finished_cb(view, frame):
+ Gtk.main_quit()
+
+Gtk.init([])
+
+win = Gtk.Window()
+webview = WebKit.WebView()
+win.add(webview)
+win.show_all()
+win.connect("destroy", Gtk.main_quit)
+
+path = sys.argv[1]
+url = GLib.filename_to_uri(path, None)
+
+helper = GWebKitJS.Helper.new(webview)
+helper.connect("window-object-cleared", win_obj_clr_cb)
+webview.load_uri(url)
+webview.connect("load-finished", load_finished_cb)
+
+Gtk.main()

No commit comments for this range

Something went wrong with that request. Please try again.