void marina_web_view_set_item (MarinaWebView *web_view, MarinaItem *item) { MarinaWebViewPrivate *priv; gchar *json; gchar *script; g_return_if_fail (MARINA_IS_WEB_VIEW (web_view)); priv = web_view->priv; if (priv->item) g_object_unref (priv->item); priv->item = item ? g_object_ref (item) : NULL; if (!priv->loaded) return; json = to_item_json (item); script = g_strconcat ("setItem(", json, ");", NULL); webkit_web_view_execute_script (WEBKIT_WEB_VIEW (priv->web_view), script); gtk_adjustment_set_value (priv->vadj, 0.0); g_free (json); g_free (script); }
void marina_web_view_set_source (MarinaWebView *web_view, MarinaSource *source) { MarinaWebViewPrivate *priv; gchar *json; gchar *script; g_return_if_fail (MARINA_IS_WEB_VIEW (web_view)); priv = web_view->priv; if (priv->source) g_object_unref (priv->source); priv->source = source ? g_object_ref (source) : NULL; /* this will get finished when its loaded */ if (!priv->loaded) return; json = to_source_json (source); script = g_strconcat ("$(function(){" " setSource(", json, ");", "});", NULL); webkit_web_view_execute_script (WEBKIT_WEB_VIEW (priv->web_view), script); g_free (json); g_free (script); }
/* ghtml_execute */ void ghtml_execute(GtkWidget * widget, char const * code) { GHtml * ghtml; ghtml = g_object_get_data(G_OBJECT(widget), "ghtml"); webkit_web_view_execute_script(WEBKIT_WEB_VIEW(ghtml->view), code); }
bool ScriptItem::invoke() const { WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); gchar* scriptString = JSStringCopyUTF8CString(m_script.get()); webkit_web_view_execute_script(webView, scriptString); g_free(scriptString); return true; }
static void test_webkit_web_view_grab_focus() { char* uri = g_strconcat(base_uri, "iframe.html", NULL); GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP); GtkWidget* scrolled_window = gtk_scrolled_window_new(NULL, NULL); WebKitWebView* view = WEBKIT_WEB_VIEW(webkit_web_view_new()); GtkAdjustment* adjustment; gtk_window_set_default_size(GTK_WINDOW(window), 400, 200); gtk_container_add(GTK_CONTAINER(window), scrolled_window); gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(view)); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); loop = g_main_loop_new(NULL, TRUE); g_signal_connect(view, "notify::load-status", G_CALLBACK(idle_quit_loop_cb), NULL); /* Wait for window to show up */ gtk_widget_show_all(window); g_signal_connect(window, "map-event", G_CALLBACK(map_event_cb), loop); g_main_loop_run(loop); /* Load a page with a big div that will cause scrollbars to appear */ webkit_web_view_load_uri(view, uri); g_main_loop_run(loop); adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolled_window)); g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), ==, 0.0); /* Since webkit_web_view_execute_script does not return a value, it is impossible to know if an inner document has focus after a node of it was focused via .focus() method. The code below is an workaround: if the node has focus, a scroll action is performed and afterward it is checked if the adjustment has to be different from 0. */ char script[] = "var innerDoc = document.defaultView.frames[0].document; \ innerDoc.getElementById(\"link\").focus(); \ if (innerDoc.hasFocus()) \ window.scrollBy(0, 100);"; /* Focus an element using JavaScript */ webkit_web_view_execute_script(view, script); /* Adjustments update asynchronously, so we must wait a bit. */ g_timeout_add(100, quit_after_short_delay_cb, loop); g_main_loop_run(loop); /* Make sure the ScrolledWindow noticed the scroll */ g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), !=, 0.0); g_free(uri); gtk_widget_destroy(window); }
void Window_add_message(Window* window, const gchar* text) { printf("%s\n", Style_get_name(style)); Message* msg = Message_new("Ben", text, MessageBuffer_get_next_id(window->_buffer)); Message_parse(msg, style); MessageBuffer_add_message(window->_buffer, msg); gchar *script_add = g_strdup_printf("append_message(\"%s\")", Message_get_parsed_text(msg)); webkit_web_view_execute_script(WEBKIT_WEB_VIEW(window->_webview), script_add); g_free(script_add); int id; if((id = MessageBuffer_message_deleted(window->_buffer)) != MESSAGEBUFFER_NO) { gchar *script_del = g_strdup_printf("delete_message(\"msg%d\")", id); webkit_web_view_execute_script(WEBKIT_WEB_VIEW(window->_webview), script_del); g_free(script_del); } }
JNIEXPORT void JNICALL WebKitGTK_NATIVE(_1webkit_1web_1view_1execute_1script) (JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1) { jbyte *lparg1=NULL; WebKitGTK_NATIVE_ENTER(env, that, _1webkit_1web_1view_1execute_1script_FUNC); if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; webkit_web_view_execute_script((WebKitWebView *)arg0, (const gchar *)lparg1); fail: if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); WebKitGTK_NATIVE_EXIT(env, that, _1webkit_1web_1view_1execute_1script_FUNC); }
void wk_html_print(WkHtml *html) { #ifdef USE_WEBKIT2 WebKitPrintOperation *print_operation; print_operation = webkit_print_operation_new(WEBKIT_WEB_VIEW(html)); webkit_print_operation_run_dialog(print_operation, NULL); #else webkit_web_frame_print(webkit_web_view_get_main_frame(WEBKIT_WEB_VIEW(html))); webkit_web_view_execute_script(WEBKIT_WEB_VIEW(html), "print();"); #endif }
static VALUE WebView_execute_script(VALUE self, VALUE __v_script) { char * script; char * __orig_script; WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); __orig_script = script = ( NIL_P(__v_script) ? NULL : StringValuePtr(__v_script) ); #line 259 "/home/ngl/Progetti/gtk-webkit-ruby/ext/webkit/webkit.cr" webkit_web_view_execute_script(_self, script); return Qnil; }
static void color_button_color_set_cb (GtkWidget* button, gpointer userdata) { GtkWidget* web_view = GTK_WIDGET (userdata); GdkColor color; gchar* script; gtk_color_button_get_color (GTK_COLOR_BUTTON (button), &color); script = g_strdup_printf ("document.body.style.backgroundColor = " "\"#%x%x%x\";", color.red / 256, color.green / 256, color.blue / 256); webkit_web_view_execute_script (WEBKIT_WEB_VIEW (web_view), script); }
static void maybe_apply_script (const char *basename, GreasemonkeyScript *script, ApplyScriptCBData *data) { char *script_str; if (!greasemonkey_script_applies_to_url (script, data->location)) return; g_object_get (script, "script", &script_str, NULL); webkit_web_view_execute_script (data->web_view, script_str); g_free (script_str); }
//#ifdef ver_3_ void new_open__(const Glib::ustring& url,WebKitWebView* wwv){ Glib::ustring js; js= "var a=document.createElement('a');"//_x "a.setAttribute('href','"+url+"');" "a.setAttribute('target','_blank');" //"a.innerHTML='a';" //"var body=document.getElementsByTagName('body')[0];" //"body.appendChild(a);" "var me=document.createEvent('MouseEvents');" "me.initEvent('click',true,false);" "a.dispatchEvent(me);" ; webkit_web_view_execute_script (wwv, js.c_str()); }
// Hack to force webview exit from fullscreen mode on new page static void liferea_webkit_load_status_changed (WebKitWebView *view, GParamSpec *pspec, gpointer user_data) { WebKitLoadStatus loadStatus; g_object_get (view, "load-status", &loadStatus, NULL); if (loadStatus == WEBKIT_LOAD_PROVISIONAL) { gboolean isFullscreen; isFullscreen = GPOINTER_TO_INT(g_object_steal_data( G_OBJECT(view), "fullscreen_on")); if (isFullscreen == TRUE) { webkit_web_view_execute_script (view, "document.webkitExitFullscreen();"); } } }
void page___::close__(){ webkit_web_view_execute_script (wwv_, "var body=document.getElementsByTagName('body')[0];" "body.parentNode.removeChild(body);" ); g_object_unref(wwv_); if(n_){ if(parent_&&sw_==n_->get_nth_page(n_->get_current_page())){ for(int pn=0;pn<n_->get_n_pages();pn++){ if(parent_==n_->get_nth_page(pn)){ n_->set_current_page(pn); break; } } } n_->remove_page(*sw_); } }
/* Callback Function for WebKit */ static void cb_load_status(WebKitWebView *web_view, GParamSpec * pspec, void * p_context) { WebKitLoadStatus status = webkit_web_view_get_load_status (web_view); GObject *object = G_OBJECT (web_view); g_object_freeze_notify (object); switch (status) { case WEBKIT_LOAD_FINISHED: printf("WEBKIT_LOAD_FINISHED\n"); // Load Javascript Language Translator char load_js_script[] = "load_js(\"blockly/lua_compressed.js\", null); setup_blockly(\"\");"; webkit_web_view_execute_script(web_view, load_js_script); break; case WEBKIT_LOAD_PROVISIONAL: printf("WEBKIT_LOAD_PROVISIONAL\n"); break; case WEBKIT_LOAD_COMMITTED: printf("WEBKIT_LOAD_COMMITTED\n"); break; case WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT: printf("WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT\n"); break; case WEBKIT_LOAD_FAILED: printf("WEBKIT_LOAD_FAILED\n"); break; default: break; } g_object_thaw_notify (object); }
void wxWebViewWebKit::RunScript(const wxString& javascript) { webkit_web_view_execute_script(WEBKIT_WEB_VIEW(web_view), javascript.mb_str(wxConvUTF8)); }
gboolean ghtml_window_escaped (GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, GdkModifierType modifier) { webkit_web_view_execute_script(ghtml_webview, "window.close();"); return true; }
static void do_test_webkit_web_view_adjustments(gboolean with_page_cache) { char* effective_uri = g_strconcat(base_uri, "bigdiv.html", NULL); char* second_uri = g_strconcat(base_uri, "iframe.html", NULL); GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); GtkWidget* scrolled_window = gtk_scrolled_window_new(NULL, NULL); WebKitWebView* view = WEBKIT_WEB_VIEW(webkit_web_view_new()); GtkAdjustment* adjustment; double lower; double upper; if (with_page_cache) { WebKitWebSettings* settings = webkit_web_view_get_settings(view); g_object_set(settings, "enable-page-cache", TRUE, NULL); } gtk_window_set_default_size(GTK_WINDOW(window), 400, 200); gtk_container_add(GTK_CONTAINER(window), scrolled_window); gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(view)); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); loop = g_main_loop_new(NULL, TRUE); g_object_connect(G_OBJECT(view), "signal::notify::progress", idle_quit_loop_cb, NULL, NULL); /* Wait for window to show up */ gtk_widget_show_all(window); g_signal_connect(window, "map-event", G_CALLBACK(map_event_cb), loop); g_main_loop_run(loop); /* Load a page with a big div that will cause scrollbars to appear */ webkit_web_view_load_uri(view, effective_uri); g_main_loop_run(loop); adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolled_window)); g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), ==, 0.0); lower = gtk_adjustment_get_lower(adjustment); upper = gtk_adjustment_get_upper(adjustment); /* Scroll the view using JavaScript */ webkit_web_view_execute_script(view, "window.scrollBy(0, 100)"); /* Make sure the ScrolledWindow noticed the scroll */ g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), ==, 100.0); /* Load a second URI */ webkit_web_view_load_uri(view, second_uri); g_main_loop_run(loop); /* Make sure the scrollbar has been reset */ g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), ==, 0.0); /* Go back */ webkit_web_view_go_back(view); /* When using page cache, go_back will return syncronously */ if (!with_page_cache) g_main_loop_run(loop); /* Make sure GTK+ has time to process the changes in size, for the adjusments */ while (gtk_events_pending()) gtk_main_iteration(); /* Make sure upper and lower bounds have been restored correctly */ g_assert_cmpfloat(lower, ==, gtk_adjustment_get_lower(adjustment)); g_assert_cmpfloat(upper, ==, gtk_adjustment_get_upper(adjustment)); g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), ==, 100.0); g_free(effective_uri); g_free(second_uri); gtk_widget_destroy(window); }
static void run_js (WebKitWebView * web_view, const gchar *param) { if (param) webkit_web_view_execute_script (web_view, param); }
void wxWebViewWebKit::RunScript(const wxString& javascript) { webkit_web_view_execute_script(m_web_view, javascript.mb_str(wxConvUTF8)); }
/* Callback Function for the Print Menu Option */ static void cb_print(GtkWidget * widget, void * p_data) { WebKitWebView * view = (WebKitWebView *)p_data; char script[] = "Sys.print(Blockly.Xml.domToPrettyText(Blockly.Xml.workspaceToDom(Blockly.mainWorkspace)));"; //char script[] = "Sys.print(Blockly.Lua.workspaceToCode());"; webkit_web_view_execute_script(view, script); }
/* Callback Function for the Build Menu Option */ static void cb_build(GtkWidget * widget, void * p_data) { WebKitWebView * view = (WebKitWebView *)p_data; char script[] = "Sys.print(Blockly.Lua.workspaceToCode());"; webkit_web_view_execute_script(view, script); }
void webview_executeScript(WebView *webview, const gchar *script) { webkit_web_view_execute_script(WEBKIT_WEB_VIEW(webview->widget), script); }