static void formhistory_frame_loaded_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, MidoriExtension* extension) { const gchar* page_uri; const gchar* count_request; FormHistoryPriv* priv; JSContextRef js_context; gchar* data; gchar* count; page_uri = webkit_web_frame_get_uri (web_frame); if (!page_uri) return; count_request = "document.querySelectorAll('input[type=password]').length"; js_context = webkit_web_frame_get_global_context (web_frame); count = sokoke_js_script_eval (js_context, count_request, NULL); if (count && count[0] == '0') { g_free (count); return; } g_free (count); priv = g_object_get_data (G_OBJECT (extension), "priv"); data = formhistory_get_login_data (priv->db, webkit_web_frame_get_uri (web_frame)); if (!data) return; formhistory_fill_login_data (js_context, priv, data); g_free (data); }
void addAccessibilityNotificationHandler(AccessibilityNotificationHandler* notificationHandler) { if (!notificationHandler) return; #if PLATFORM(GTK) JSGlobalContextRef jsContext = webkit_web_frame_get_global_context(mainFrame); #else JSContextRef jsContext = 0; #endif if (!jsContext) return; JSValueProtect(jsContext, notificationHandler->notificationFunctionCallback()); // Check if this notification handler is related to a specific element. if (notificationHandler->platformElement()) { if (notificationHandlers.contains(notificationHandler->platformElement())) { JSValueUnprotect(jsContext, notificationHandlers.find(notificationHandler->platformElement())->value->notificationFunctionCallback()); notificationHandlers.remove(notificationHandler->platformElement()); } notificationHandlers.add(notificationHandler->platformElement(), notificationHandler); } else { if (notificationHandlers.contains(GlobalNotificationKey)) { JSValueUnprotect(jsContext, notificationHandlers.find(GlobalNotificationKey)->value->notificationFunctionCallback()); notificationHandlers.remove(GlobalNotificationKey); } notificationHandlers.add(GlobalNotificationKey, notificationHandler); } connectAccessibilityCallbacks(); }
static void test_ime_load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data) { KeyEventFixture* fixture = (KeyEventFixture*)data; WebKitLoadStatus status = webkit_web_view_get_load_status(webView); if (status != WEBKIT_LOAD_FINISHED) return; JSGlobalContextRef context = webkit_web_frame_get_global_context( webkit_web_view_get_main_frame(webView)); g_assert(context); GtkIMContext* imContext = 0; g_object_get(webView, "im-context", &imContext, NULL); g_assert(imContext); // Test that commits that happen outside of key events // change the text field immediately. This closely replicates // the behavior of SCIM. g_assert(element_text_equal_to(context, "")); g_signal_emit_by_name(imContext, "commit", "a"); g_assert(element_text_equal_to(context, "a")); g_signal_emit_by_name(imContext, "commit", "b"); g_assert(element_text_equal_to(context, "ab")); g_signal_emit_by_name(imContext, "commit", "c"); g_assert(element_text_equal_to(context, "abc")); g_object_unref(imContext); g_main_loop_quit(fixture->loop); }
void removeAccessibilityNotificationHandler(AccessibilityNotificationHandler* notificationHandler) { if (!notificationHandler) return; #if PLATFORM(GTK) JSGlobalContextRef jsContext = webkit_web_frame_get_global_context(mainFrame); #elif PLATFORM(EFL) JSGlobalContextRef jsContext = DumpRenderTreeSupportEfl::globalContextRefForFrame(browser->mainFrame()); #else JSGlobalContextRef jsContext = 0; #endif if (!jsContext) return; if (globalNotificationHandler == notificationHandler) { JSValueUnprotect(jsContext, globalNotificationHandler->notificationFunctionCallback()); globalNotificationHandler = 0; } else if (notificationHandler->platformElement()) { NotificationHandlersMap::iterator removeNotificationHandler = notificationHandlers.find(notificationHandler->platformElement()); if (removeNotificationHandler != notificationHandlers.end()) { JSValueUnprotect(jsContext, removeNotificationHandler->value->notificationFunctionCallback()); notificationHandlers.remove(removeNotificationHandler); } } }
void addAccessibilityNotificationHandler(AccessibilityNotificationHandler* notificationHandler) { if (!notificationHandler) return; #if PLATFORM(GTK) JSGlobalContextRef jsContext = webkit_web_frame_get_global_context(mainFrame); #elif PLATFORM(EFL) JSGlobalContextRef jsContext = DumpRenderTreeSupportEfl::globalContextRefForFrame(browser->mainFrame()); #else JSContextRef jsContext = 0; #endif if (!jsContext) return; JSValueProtect(jsContext, notificationHandler->notificationFunctionCallback()); // Check if this notification handler is related to a specific element. if (notificationHandler->platformElement()) { NotificationHandlersMap::iterator currentNotificationHandler = notificationHandlers.find(notificationHandler->platformElement()); if (currentNotificationHandler != notificationHandlers.end()) { ASSERT(currentNotificationHandler->value->platformElement()); JSValueUnprotect(jsContext, currentNotificationHandler->value->notificationFunctionCallback()); notificationHandlers.remove(currentNotificationHandler->value->platformElement()); } notificationHandlers.add(notificationHandler->platformElement(), notificationHandler); } else { if (globalNotificationHandler) JSValueUnprotect(jsContext, globalNotificationHandler->notificationFunctionCallback()); globalNotificationHandler = notificationHandler; } connectAccessibilityCallbacks(); }
int main (int argc, gchar* argv[]) { GtkWidget* window; GtkWidget* vbox; GtkWidget* scrolled; GtkWidget* web_view; GtkWidget* button_box; WebKitWebFrame* web_frame; JSGlobalContextRef js_context; JSObjectRef js_global; JSStringRef js_function_name; JSObjectRef js_set_can_register; if (!g_thread_supported ()) g_thread_init (NULL); gtk_init_check (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "WebKitGTK+ API Demo"); gtk_window_set_default_size (GTK_WINDOW (window), 640, 240); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); vbox = gtk_vbox_new (FALSE, 4); gtk_container_add (GTK_CONTAINER (window), vbox); scrolled = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX (vbox), scrolled, TRUE, TRUE, 0); web_view = webkit_web_view_new (); gtk_container_add (GTK_CONTAINER (scrolled), web_view); webkit_web_view_load_string (WEBKIT_WEB_VIEW (web_view), form_markup, "text/html", "UTF-8", ""); g_signal_connect (web_view, "create-plugin-widget", G_CALLBACK (web_view_create_plugin_widget_cb), NULL); button_box = gtk_hbutton_box_new (); gtk_box_pack_start (GTK_BOX (vbox), button_box, FALSE, FALSE, 0); register_button = gtk_button_new_with_mnemonic ("Send _Registration"); gtk_widget_set_sensitive (register_button, FALSE); gtk_box_pack_start (GTK_BOX (button_box), register_button, FALSE, FALSE, 0); web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view)); js_context = webkit_web_frame_get_global_context (web_frame); js_global = JSContextGetGlobalObject (js_context); js_function_name = JSStringCreateWithUTF8CString ("setCanRegister"); js_set_can_register = JSObjectMakeFunctionWithCallback (js_context, js_function_name, (JSObjectCallAsFunctionCallback)set_can_register_cb); JSObjectSetProperty (js_context, js_global, js_function_name, js_set_can_register, 0, NULL); JSStringRelease (js_function_name); gtk_widget_show_all (window); gtk_main (); return 0; }
JNIEXPORT jintLong JNICALL WebKitGTK_NATIVE(_1webkit_1web_1frame_1get_1global_1context) (JNIEnv *env, jclass that, jintLong arg0) { jintLong rc = 0; WebKitGTK_NATIVE_ENTER(env, that, _1webkit_1web_1frame_1get_1global_1context_FUNC); rc = (jintLong)webkit_web_frame_get_global_context((WebKitWebFrame *)arg0); WebKitGTK_NATIVE_EXIT(env, that, _1webkit_1web_1frame_1get_1global_1context_FUNC); return rc; }
static VALUE WebFrame_add_ruby_eval(VALUE self) { WebKitWebFrame *_self = ((WebKitWebFrame*)RVAL2GOBJ(self)); #line 83 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" javascript_add_ruby_eval(webkit_web_frame_get_global_context(_self)); return Qnil; }
static VALUE WebFrame_setup_ruby(VALUE self) { WebKitWebFrame *_self = ((WebKitWebFrame*)RVAL2GOBJ(self)); #line 241 "/home/ngl/Progetti/gtk-webkit-ruby/ext/webkit/webkit.cr" javascript_setup_ruby(webkit_web_frame_get_global_context(_self)); return Qnil; }
static gboolean verify_contents(gpointer data) { KeyEventFixture* fixture = (KeyEventFixture*)data; JSGlobalContextRef context = webkit_web_frame_get_global_context( webkit_web_view_get_main_frame(fixture->webView)); g_assert(context); g_assert(element_text_equal_to(context, fixture->info->text)); g_main_loop_quit(fixture->loop); return FALSE; }
void hints_init(WebKitWebFrame *frame) { if (hints.obj) { JSValueUnprotect(hints.ctx, hints.obj); hints.obj = NULL; } if (!hints.obj) { hints.ctx = webkit_web_frame_get_global_context(frame); hints.obj = js_create_object(hints.ctx, HINTS_JS); } }
static VALUE WebFrame_exec_js(VALUE self, VALUE __v_js) { VALUE __p_retval = Qnil; char * js; char * __orig_js; WebKitWebFrame *_self = ((WebKitWebFrame*)RVAL2GOBJ(self)); __orig_js = js = ( NIL_P(__v_js) ? NULL : StringValuePtr(__v_js) ); #line 238 "/home/ngl/Progetti/gtk-webkit-ruby/ext/webkit/webkit.cr" do { __p_retval = javascript_exec(webkit_web_frame_get_global_context(_self), js); goto out; } while(0); out: return __p_retval; }
static VALUE WebFrame_add_js_api(VALUE self, VALUE __v_name) { char * name; char * __orig_name; WebKitWebFrame *_self = ((WebKitWebFrame*)RVAL2GOBJ(self)); __orig_name = name = ( NIL_P(__v_name) ? NULL : StringValuePtr(__v_name) ); VALUE block = rb_block_proc(); #line 244 "/home/ngl/Progetti/gtk-webkit-ruby/ext/webkit/webkit.cr" javascript_add_ruby_fn(webkit_web_frame_get_global_context(_self), name, block); return Qnil; }
static VALUE WebFrame_add_ruby_class(VALUE self, VALUE __v_name, VALUE klass) { char * name; char * __orig_name; WebKitWebFrame *_self = ((WebKitWebFrame*)RVAL2GOBJ(self)); __orig_name = name = ( NIL_P(__v_name) ? NULL : StringValuePtr(__v_name) ); if (! ((TYPE(klass) == T_CLASS) || (TYPE(klass) == T_MODULE)) ) rb_raise(rb_eArgError, "klass argument must be one of Class, Module"); #line 80 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" javascript_add_class(webkit_web_frame_get_global_context(_self), name, klass); return Qnil; }
void mk_zs__(WebKitWebView* wwv){ WebKitWebFrame* web_frame; JSGlobalContextRef js_context; JSObjectRef js_global; JSStringRef js_function_name; JSObjectRef js_function; web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (wwv)); js_context = webkit_web_frame_get_global_context (web_frame); js_global = JSContextGetGlobalObject (js_context); js_function_name = JSStringCreateWithUTF8CString (s1_[zs_].c_str()); js_function = JSObjectMakeFunctionWithCallback (js_context, js_function_name, zs__); JSObjectSetProperty (js_context, js_global, js_function_name, js_function, kJSPropertyAttributeNone, NULL); JSStringRelease (js_function_name); }
void* plat_create_window(void* tag, int w, int h) { struct gtk_state* state = malloc(sizeof(struct gtk_state)); state->tag = tag; GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "WebUI"); state->window = window; gtk_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(close_window), state); GtkWidget* scroll = gtk_scrolled_window_new(NULL, NULL); state->web_view = webkit_web_view_new(); gtk_container_add(GTK_CONTAINER(scroll), state->web_view); gtk_container_add(GTK_CONTAINER(window), scroll); WebKitWebFrame* web_frame = webkit_web_view_get_main_frame( WEBKIT_WEB_VIEW(state->web_view)); gtk_window_set_default_size(GTK_WINDOW(window), w, h); gtk_widget_show_all(window); JSGlobalContextRef jsctx = webkit_web_frame_get_global_context(web_frame); state->jsctx = jsctx; JSClassDefinition system_def = kJSClassDefinitionEmpty; system_def.className = "ruby"; system_def.getProperty = ruby_getprop; JSClassRef system_class = JSClassCreate(&system_def); JSObjectRef o = JSObjectMake(jsctx, system_class, NULL); if(!JSObjectSetPrivate(o, tag)) { printf("WebKit is busted.\n"); abort(); } JSStringRef name = JSStringCreateWithUTF8CString("ruby"); JSObjectSetProperty(jsctx, JSContextGetGlobalObject(jsctx), name, o, kJSPropertyAttributeDontDelete, NULL); JSStringRelease(name); return state; }
static void webview_register_function(WebKitWebFrame *frame, const gchar *name, gpointer ref) { JSGlobalContextRef context = webkit_web_frame_get_global_context(frame); JSStringRef js_name = JSStringCreateWithUTF8CString(name); // prepare callback function JSClassDefinition def = kJSClassDefinitionEmpty; def.callAsFunction = webview_registered_function_callback; def.className = g_strdup(name); def.finalize = webview_collect_registered_function; JSClassRef class = JSClassCreate(&def); JSObjectRef fun = JSObjectMake(context, class, ref); // register with global object JSObjectRef global = JSContextGetGlobalObject(context); JSObjectSetProperty(context, global, js_name, fun, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, NULL); // release strings JSStringRelease(js_name); JSClassRelease(class); }
void removeAccessibilityNotificationHandler(AccessibilityNotificationHandler* notificationHandler) { if (!notificationHandler) return; #if PLATFORM(GTK) JSGlobalContextRef jsContext = webkit_web_frame_get_global_context(mainFrame); #else JSGlobalContextRef jsContext = 0; #endif if (!jsContext) return; for (HashMap<PlatformUIElement, AccessibilityNotificationHandler*>::iterator it = notificationHandlers.begin(); it != notificationHandlers.end(); ++it) { if (it->value == notificationHandler) { JSValueUnprotect(jsContext, notificationHandler->notificationFunctionCallback()); notificationHandlers.remove(it); } } }
WebKitWebView* wwv__(JSContextRef js_context){ WebKitWebView* wwv2=jscr2wwv_[js_context]; if(!wwv2){ map<WebKitWebView*,control___*>::iterator mi; JSObjectRef or1 = JSContextGetGlobalObject(js_context); for(mi=names_.begin();mi!=names_.end();mi++){ WebKitWebView* wwv=mi->first; WebKitWebFrame *wwf=webkit_web_view_get_main_frame(wwv); if(wwf){ JSGlobalContextRef gcr=webkit_web_frame_get_global_context(wwf); if(gcr){ JSObjectRef or2=JSContextGetGlobalObject(gcr); if(or1==or2){ jscr2wwv_[js_context]=wwv2=wwv; break; } } } } } return wwv2; }
int main(int argc, char** argv) { gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), NULL); g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); web_view = WEBKIT_WEB_VIEW(webkit_web_view_new()); webFrame = webkit_web_view_get_main_frame (web_view); context = webkit_web_frame_get_global_context(webFrame); globalObject = JSContextGetGlobalObject(context); setlogmask (LOG_UPTO (LOG_NOTICE)); openlog ("kioskbrowser", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); signal(SIGHUP, reload_browser); signal(SIGUSR1, jsmessage); signal(SIGUSR2, jsmessage); gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(web_view)); if(argc > 1) { webkit_web_view_load_uri(web_view, argv[1]); } else { webkit_web_view_load_uri(web_view, default_url); } maximize(); gtk_widget_show_all(window); gtk_main(); return 0; }
static gboolean formhistory_navigation_decision_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, WebKitNetworkRequest* request, WebKitWebNavigationAction* action, WebKitWebPolicyDecision* decision, MidoriExtension* extension) { FormHistoryPriv* priv; JSContextRef js_context; gchar* value; /* The script returns form data in the form "field_name|,|value|,|field_type". We are handling only input fields with 'text' or 'password' type. The field separator is "|||" */ const gchar* script = "function dumpForm (inputs) {" " var out = '';" " for (var i = 0; i < inputs.length; i++) {" " if (inputs[i].getAttribute('autocomplete') == 'off' && " " inputs[i].type == 'text')" " continue;" " if (inputs[i].value && (inputs[i].type == 'text' || inputs[i].type == 'password')) {" " var ename = inputs[i].getAttribute('name');" " var eid = inputs[i].getAttribute('id');" " if (!eid && ename)" " eid=ename;" " out += eid+'|,|'+inputs[i].value +'|,|'+inputs[i].type +'|||';" " }" " }" " return out;" "}" "dumpForm (document.getElementsByTagName('input'))"; if (webkit_web_navigation_action_get_reason (action) != WEBKIT_WEB_NAVIGATION_REASON_FORM_SUBMITTED) return FALSE; priv = g_object_get_data (G_OBJECT (extension), "priv"); js_context = webkit_web_frame_get_global_context (web_frame); value = sokoke_js_script_eval (js_context, script, NULL); formhistory_suggestions_hide_cb (NULL, NULL, priv); if (value && *value) { gchar** inputs = g_strsplit (value, "|||", 0); guint i = 0; while (inputs[i] != NULL) { gchar** parts = g_strsplit (inputs[i], "|,|", 3); if (parts && parts[0] && parts[1] && parts[2]) { if (strcmp (parts[2], "password")) formhistory_update_database (priv->db, NULL, parts[0], parts[1]); else { #if 0 FormhistoryPasswordEntry* entry; #endif gchar* data = formhistory_get_login_data (priv->db, webkit_web_frame_get_uri (web_frame)); if (data) { g_free (data); break; } #if 0 entry = g_slice_new (FormhistoryPasswordEntry); /* Domain and form data are freed from infopanel callback*/ entry->form_data = g_strdup (value); entry->domain = domain; entry->priv = priv; g_object_set_data (G_OBJECT (web_view), "FormHistoryPasswordEntry", entry); #endif } } g_strfreev (parts); i++; } g_strfreev (inputs); g_free (value); } return FALSE; }
WebView *webView = [[WebView alloc] init]; JSGlobalContextRef _context = [[webView mainFrame] globalContext]; #elif WEBKIT_DEBUG NSAutoreleasePool *pool = [NSAutoreleasePool new]; WebView *webView = NW_init(argc, argv, envp); JSGlobalContextRef _context = [[webView mainFrame] globalContext]; #elif defined(JSCOCOA) NSAutoreleasePool *pool = [NSAutoreleasePool new]; JSCocoaController *jsc = [JSCocoa new]; JSGlobalContextRef _context = [jsc ctx]; #elif defined(WEBKIT_GTK) gtk_init(0, NULL); WebKitWebView* view = webkit_web_view_new(); WebKitWebFrame* frame = webkit_web_view_get_main_frame(view); JSGlobalContextRef _context = webkit_web_frame_get_global_context(frame); #else JSGlobalContextRef _context = JSGlobalContextCreate(NULL); #endif #ifdef WEBKIT_DEBUG return NSApplicationMain(argc, (const char **)argv); #else JSValueRef exception = NULL; JSValueRef *_exception = &exception; CALL(narwhal, argc, argv, envp, 1); int code = !!(*_exception); #ifdef WEBKIT
Client * newclient(void) { Client *c; WebKitWebSettings *settings; WebKitWebFrame *frame; GdkGeometry hints = { 1, 1 }; char *uri, *ua; if(!(c = calloc(1, sizeof(Client)))) die("Cannot malloc!\n"); /* Window */ if(embed) { c->win = gtk_plug_new(embed); } else { c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* TA: 20091214: Despite what the GNOME docs say, the ICCCM * is always correct, so we should still call this function. * But when doing so, we *must* differentiate between a * WM_CLASS and a resource on the window. By convention, the * window class (WM_CLASS) is capped, while the resource is in * lowercase. Both these values come as a pair. */ gtk_window_set_wmclass(GTK_WINDOW(c->win), "surf", "surf"); /* TA: 20091214: And set the role here as well -- so that * sessions can pick this up. */ gtk_window_set_role(GTK_WINDOW(c->win), "Surf"); } gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600); g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c); g_signal_connect(G_OBJECT(c->win), "key-press-event", G_CALLBACK(keypress), c); g_signal_connect(G_OBJECT(c->win), "size-allocate", G_CALLBACK(resize), c); /* VBox */ c->vbox = gtk_vbox_new(FALSE, 0); /* Scrolled Window */ c->scroll = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(c->scroll), GTK_POLICY_NEVER, GTK_POLICY_NEVER); /* Webview */ c->view = WEBKIT_WEB_VIEW(webkit_web_view_new()); g_signal_connect(G_OBJECT(c->view), "button-press-event", G_CALLBACK(buttonevent), c); g_signal_connect(G_OBJECT(c->view), "title-changed", G_CALLBACK(titlechange), c); g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c); g_signal_connect(G_OBJECT(c->view), "create-web-view", G_CALLBACK(createwindow), c); g_signal_connect(G_OBJECT(c->view), "new-window-policy-decision-requested", G_CALLBACK(decidewindow), c); g_signal_connect(G_OBJECT(c->view), "mime-type-policy-decision-requested", G_CALLBACK(decidedownload), c); g_signal_connect(G_OBJECT(c->view), "window-object-cleared", G_CALLBACK(windowobjectcleared), c); g_signal_connect(G_OBJECT(c->view), "notify::load-status", G_CALLBACK(loadstatuschange), c); g_signal_connect(G_OBJECT(c->view), "notify::progress", G_CALLBACK(progresschange), c); g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c); /* Indicator */ c->indicator = gtk_drawing_area_new(); gtk_widget_set_size_request(c->indicator, 0, 2); g_signal_connect (G_OBJECT (c->indicator), "expose_event", G_CALLBACK (exposeindicator), c); /* Arranging */ gtk_container_add(GTK_CONTAINER(c->scroll), GTK_WIDGET(c->view)); gtk_container_add(GTK_CONTAINER(c->win), c->vbox); gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll); gtk_container_add(GTK_CONTAINER(c->vbox), c->indicator); /* Setup */ gtk_box_set_child_packing(GTK_BOX(c->vbox), c->indicator, FALSE, FALSE, 0, GTK_PACK_START); gtk_box_set_child_packing(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 0, GTK_PACK_START); gtk_widget_grab_focus(GTK_WIDGET(c->view)); gtk_widget_show(c->vbox); gtk_widget_show(c->indicator); gtk_widget_show(c->scroll); gtk_widget_show(GTK_WIDGET(c->view)); gtk_widget_show(c->win); gtk_window_set_geometry_hints(GTK_WINDOW(c->win), NULL, &hints, GDK_HINT_MIN_SIZE); gdk_window_set_events(GTK_WIDGET(c->win)->window, GDK_ALL_EVENTS_MASK); gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c); webkit_web_view_set_full_content_zoom(c->view, TRUE); frame = webkit_web_view_get_main_frame(c->view); runscript(frame, webkit_web_frame_get_global_context(frame)); settings = webkit_web_view_get_settings(c->view); if(!(ua = getenv("SURF_USERAGENT"))) ua = useragent; g_object_set(G_OBJECT(settings), "user-agent", ua, NULL); uri = g_strconcat("file://", stylefile, NULL); g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL); g_object_set(G_OBJECT(settings), "auto-load-images", loadimage, NULL); g_object_set(G_OBJECT(settings), "enable-plugins", plugin, NULL); g_object_set(G_OBJECT(settings), "enable-scripts", script, NULL); g_object_set(G_OBJECT(settings), "enable-spatial-navigation", true, NULL); g_free(uri); setatom(c, AtomFind, ""); setatom(c, AtomUri, "about:blank"); if(NOBACKGROUND) webkit_web_view_set_transparent(c->view, TRUE); c->title = NULL; c->next = clients; clients = c; if(showxid) { gdk_display_sync(gtk_widget_get_display(c->win)); printf("%u\n", (guint)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window)); fflush(NULL); } return c; }
static gboolean axObjectEventListener(GSignalInvocationHint *signalHint, guint numParamValues, const GValue *paramValues, gpointer data) { // At least we should receive the instance emitting the signal. if (numParamValues < 1) return TRUE; AtkObject* accessible = ATK_OBJECT(g_value_get_object(¶mValues[0])); if (!accessible || !ATK_IS_OBJECT(accessible)) return TRUE; GSignalQuery signalQuery; GOwnPtr<gchar> signalName; GOwnPtr<gchar> signalValue; String notificationName; g_signal_query(signalHint->signal_id, &signalQuery); if (!g_strcmp0(signalQuery.signal_name, "state-change")) { signalName.set(g_strdup_printf("state-change:%s", g_value_get_string(¶mValues[1]))); signalValue.set(g_strdup_printf("%d", g_value_get_boolean(¶mValues[2]))); if (!g_strcmp0(g_value_get_string(¶mValues[1]), "checked")) notificationName = "CheckedStateChanged"; } else if (!g_strcmp0(signalQuery.signal_name, "focus-event")) { signalName.set(g_strdup("focus-event")); signalValue.set(g_strdup_printf("%d", g_value_get_boolean(¶mValues[1]))); notificationName = "AXFocusedUIElementChanged"; } else if (!g_strcmp0(signalQuery.signal_name, "children-changed")) { signalName.set(g_strdup("children-changed")); signalValue.set(g_strdup_printf("%d", g_value_get_uint(¶mValues[1]))); } else if (!g_strcmp0(signalQuery.signal_name, "property-change")) signalName.set(g_strdup_printf("property-change:%s", g_quark_to_string(signalHint->detail))); else signalName.set(g_strdup(signalQuery.signal_name)); if (loggingAccessibilityEvents) printAccessibilityEvent(accessible, signalName.get(), signalValue.get()); #if PLATFORM(GTK) JSGlobalContextRef jsContext = webkit_web_frame_get_global_context(mainFrame); #else JSContextRef jsContext = 0; #endif if (!jsContext) return TRUE; if (notificationName.length()) { for (HashMap<PlatformUIElement, AccessibilityNotificationHandler*>::iterator it = notificationHandlers.begin(); it != notificationHandlers.end(); ++it) { if (it->key == accessible || it->key == GlobalNotificationKey) { JSRetainPtr<JSStringRef> jsNotificationEventName(Adopt, JSStringCreateWithUTF8CString(reinterpret_cast<const char*>(notificationName.utf8().data()))); JSValueRef notificationNameArgument = JSValueMakeString(jsContext, jsNotificationEventName.get()); AccessibilityNotificationHandler* notificationHandler = it->value; if (notificationHandler->platformElement()) { JSValueRef argument = notificationNameArgument; // Listener for one element just gets one argument, the notification name. JSObjectCallAsFunction(jsContext, notificationHandler->notificationFunctionCallback(), 0, 1, &argument, 0); } else { // A global listener gets the element and the notification name as arguments. JSValueRef arguments[2]; arguments[0] = AccessibilityUIElement::makeJSAccessibilityUIElement(jsContext, AccessibilityUIElement(accessible)); arguments[1] = notificationNameArgument; JSObjectCallAsFunction(jsContext, notificationHandler->notificationFunctionCallback(), 0, 2, arguments, 0); } } } } return TRUE; }
static const gchar* webview_eval_js(WebKitWebFrame *frame, const gchar *script, const gchar *file) { JSGlobalContextRef context; JSObjectRef globalobject; JSStringRef js_file; JSStringRef js_script; JSValueRef js_result; JSValueRef js_exc = NULL; JSStringRef js_result_string; GString *result = g_string_new(NULL); size_t js_result_size; context = webkit_web_frame_get_global_context(frame); globalobject = JSContextGetGlobalObject(context); /* evaluate the script and get return value*/ js_script = JSStringCreateWithUTF8CString(script); js_file = JSStringCreateWithUTF8CString(file); js_result = JSEvaluateScript(context, js_script, globalobject, js_file, 0, &js_exc); if (js_result && !JSValueIsUndefined(context, js_result)) { js_result_string = JSValueToStringCopy(context, js_result, NULL); js_result_size = JSStringGetMaximumUTF8CStringSize(js_result_string); if (js_result_size) { gchar js_result_utf8[js_result_size]; JSStringGetUTF8CString(js_result_string, js_result_utf8, js_result_size); g_string_assign(result, js_result_utf8); } JSStringRelease(js_result_string); } else if (js_exc) { size_t size; JSStringRef prop, val; JSObjectRef exc = JSValueToObject(context, js_exc, NULL); g_printf("Exception occured while executing script:\n"); /* Print file */ prop = JSStringCreateWithUTF8CString("sourceURL"); val = JSValueToStringCopy(context, JSObjectGetProperty(context, exc, prop, NULL), NULL); size = JSStringGetMaximumUTF8CStringSize(val); if(size) { gchar cstr[size]; JSStringGetUTF8CString(val, cstr, size); g_printf("At %s", cstr); } JSStringRelease(prop); JSStringRelease(val); /* Print line */ prop = JSStringCreateWithUTF8CString("line"); val = JSValueToStringCopy(context, JSObjectGetProperty(context, exc, prop, NULL), NULL); size = JSStringGetMaximumUTF8CStringSize(val); if(size) { gchar cstr[size]; JSStringGetUTF8CString(val, cstr, size); g_printf(":%s: ", cstr); } JSStringRelease(prop); JSStringRelease(val); /* Print message */ val = JSValueToStringCopy(context, exc, NULL); size = JSStringGetMaximumUTF8CStringSize(val); if(size) { gchar cstr[size]; JSStringGetUTF8CString(val, cstr, size); g_printf("%s\n", cstr); } JSStringRelease(val); } /* cleanup */ JSStringRelease(js_script); JSStringRelease(js_file); return g_string_free(result, FALSE); }
static gboolean axObjectEventListener(GSignalInvocationHint *signalHint, guint numParamValues, const GValue *paramValues, gpointer data) { // At least we should receive the instance emitting the signal. if (numParamValues < 1) return true; AtkObject* accessible = ATK_OBJECT(g_value_get_object(¶mValues[0])); if (!accessible || !ATK_IS_OBJECT(accessible)) return true; GSignalQuery signalQuery; GUniquePtr<gchar> signalName; GUniquePtr<gchar> signalValue; String notificationName; g_signal_query(signalHint->signal_id, &signalQuery); if (!g_strcmp0(signalQuery.signal_name, "state-change")) { signalName.reset(g_strdup_printf("state-change:%s", g_value_get_string(¶mValues[1]))); signalValue.reset(g_strdup_printf("%d", g_value_get_boolean(¶mValues[2]))); if (!g_strcmp0(g_value_get_string(¶mValues[1]), "checked")) notificationName = "CheckedStateChanged"; else if (!g_strcmp0(g_value_get_string(¶mValues[1]), "invalid-entry")) notificationName = "AXInvalidStatusChanged"; } else if (!g_strcmp0(signalQuery.signal_name, "focus-event")) { signalName.reset(g_strdup("focus-event")); signalValue.reset(g_strdup_printf("%d", g_value_get_boolean(¶mValues[1]))); if (g_value_get_boolean(¶mValues[1])) notificationName = "AXFocusedUIElementChanged"; } else if (!g_strcmp0(signalQuery.signal_name, "children-changed")) { const gchar* childrenChangedDetail = g_quark_to_string(signalHint->detail); signalName.reset(g_strdup_printf("children-changed:%s", childrenChangedDetail)); signalValue.reset(g_strdup_printf("%d", g_value_get_uint(¶mValues[1]))); notificationName = !g_strcmp0(childrenChangedDetail, "add") ? "AXChildrenAdded" : "AXChildrenRemoved"; } else if (!g_strcmp0(signalQuery.signal_name, "property-change")) { signalName.reset(g_strdup_printf("property-change:%s", g_quark_to_string(signalHint->detail))); if (!g_strcmp0(g_quark_to_string(signalHint->detail), "accessible-value")) notificationName = "AXValueChanged"; } else if (!g_strcmp0(signalQuery.signal_name, "load-complete")) notificationName = "AXLoadComplete"; else signalName.reset(g_strdup(signalQuery.signal_name)); if (loggingAccessibilityEvents) printAccessibilityEvent(accessible, signalName.get(), signalValue.get()); #if PLATFORM(GTK) JSGlobalContextRef jsContext = webkit_web_frame_get_global_context(mainFrame); #elif PLATFORM(EFL) JSGlobalContextRef jsContext = DumpRenderTreeSupportEfl::globalContextRefForFrame(browser->mainFrame()); #else JSContextRef jsContext = 0; #endif if (!jsContext) return true; if (notificationName.length()) { JSRetainPtr<JSStringRef> jsNotificationEventName(Adopt, JSStringCreateWithUTF8CString(notificationName.utf8().data())); JSValueRef notificationNameArgument = JSValueMakeString(jsContext, jsNotificationEventName.get()); NotificationHandlersMap::iterator elementNotificationHandler = notificationHandlers.find(accessible); if (elementNotificationHandler != notificationHandlers.end()) { // Listener for one element just gets one argument, the notification name. JSObjectCallAsFunction(jsContext, elementNotificationHandler->value->notificationFunctionCallback(), 0, 1, ¬ificationNameArgument, 0); } if (globalNotificationHandler) { // A global listener gets the element and the notification name as arguments. JSValueRef arguments[2]; arguments[0] = AccessibilityUIElement::makeJSAccessibilityUIElement(jsContext, AccessibilityUIElement(accessible)); arguments[1] = notificationNameArgument; JSObjectCallAsFunction(jsContext, globalNotificationHandler->notificationFunctionCallback(), 0, 2, arguments, 0); } } return true; }