summaryrefslogtreecommitdiff
path: root/src/scratchpad.c
diff options
context:
space:
mode:
authorportix <none@none>2012-10-03 15:31:23 +0200
committerportix <none@none>2012-10-03 15:31:23 +0200
commit5b74b52416b90d9ade35b99f2d105a4120b0187d (patch)
tree1215d3eb5d24b6fb6dcc01c5e82700bedbd2b158 /src/scratchpad.c
parent7d0376d67895abcddd7e540c61f458400c91e1a6 (diff)
downloaddwb-5b74b52416b90d9ade35b99f2d105a4120b0187d.zip
scratchpad: communication between scripts and scratchpad
Diffstat (limited to 'src/scratchpad.c')
-rw-r--r--src/scratchpad.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/scratchpad.c b/src/scratchpad.c
index 4ae25848..00fc0974 100644
--- a/src/scratchpad.c
+++ b/src/scratchpad.c
@@ -17,6 +17,9 @@
*/
#include "dwb.h"
+#include "js.h"
+#include "scripts.h"
+#include <JavaScriptCore/JavaScript.h>
GtkWidget *g_scratchpad;
static gboolean
@@ -30,6 +33,32 @@ navigation_cb(WebKitWebView *wv, WebKitWebFrame *frame, WebKitNetworkRequest *re
return false;
}
+
+static JSValueRef
+sp_send(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception) {
+ if (argc > 0)
+ scripts_scratchpad_send(ctx, argv[0]);
+ return JSValueMakeUndefined(ctx);
+}
+
+static JSValueRef
+sp_get(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc) {
+ scripts_scratchpad_get(ctx, function, this, argc, argv, exc);
+ return JSValueMakeUndefined(ctx);
+}
+
+static void
+window_object_cb(WebKitWebView *wv, WebKitWebFrame *frame, JSContextRef ctx, JSObjectRef window) {
+ if (frame == webkit_web_view_get_main_frame(wv)) {
+ JSObjectRef func = JSObjectMakeFunctionWithCallback(ctx, NULL, sp_get);
+ js_set_property(ctx, window, "dwbGet", func,
+ kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, NULL);
+ func = JSObjectMakeFunctionWithCallback(ctx, NULL, sp_send);
+ js_set_property(ctx, window, "dwbSend", func,
+ kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, NULL);
+ }
+}
+
void
scratchpad_load(const char *text) {
if (g_str_has_prefix(text, "file://"))
@@ -43,22 +72,24 @@ scratchpad_show(void) {
gtk_widget_show(g_scratchpad);
gtk_widget_grab_focus(g_scratchpad);
}
+
void
scratchpad_hide(void) {
gtk_widget_hide(g_scratchpad);
dwb_focus_scroll(dwb.state.fview);
}
+
static void
scratchpad_init(void) {
g_scratchpad = webkit_web_view_new();
g_signal_connect(g_scratchpad, "navigation-policy-decision-requested", G_CALLBACK(navigation_cb), NULL);
+ g_signal_connect(g_scratchpad, "window-object-cleared", G_CALLBACK(window_object_cb), NULL);
gtk_widget_set_size_request(g_scratchpad, -1, 200);
}
+
GtkWidget *
scratchpad_get(void) {
if (g_scratchpad == NULL)
scratchpad_init();
return g_scratchpad;
}
-
-