void browser_window_load_uri(BrowserWindow *window, const char *uri) { g_return_if_fail(BROWSER_IS_WINDOW(window)); g_return_if_fail(uri); if (!g_str_has_prefix(uri, "javascript:")) { char *internalURI = getInternalURI(uri); if (!g_uri_parse_scheme (uri)) { internalURI = g_strconcat("http://", internalURI, NULL); } if (!internalURI || !strncasecmp (internalURI, "http:", 5) || !strncasecmp (internalURI, "https:", 6) || !strncasecmp (internalURI, "file:", 5) || !strncasecmp (internalURI, "minibrowser-about:", 18)) { g_printerr("\n\t ok!\n"); } else return; webkit_web_view_load_uri(window->webView, internalURI); g_free(internalURI); return; } webkit_web_view_run_javascript(window->webView, strstr(uri, "javascript:"), NULL, NULL, NULL); }
void wxWebViewWebKit::RunScript(const wxString& javascript) { webkit_web_view_run_javascript(m_web_view, javascript.mb_str(wxConvUTF8), NULL, NULL, NULL); }
WebKitJavascriptResult* WebViewTest::runJavaScriptAndWaitUntilFinished(const char* javascript, GError** error) { if (m_javascriptResult) webkit_javascript_result_unref(m_javascriptResult); m_javascriptResult = 0; m_javascriptError = error; webkit_web_view_run_javascript(m_webView, javascript, 0, reinterpret_cast<GAsyncReadyCallback>(runJavaScriptReadyCallback), this); g_main_loop_run(m_mainLoop); return m_javascriptResult; }
void ready_to_show(WebKitWebView *webView) { printf("---------------ready-to-show\n"); //webkit_web_view_get_snapshot(webView, // WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, // WEBKIT_SNAPSHOT_OPTIONS_NONE, // NULL, // get_snapshot_finish, // webView // ); const gchar *script = "JSON.stringify(window.performance.timing)"; webkit_web_view_run_javascript(webView, script, NULL, web_view_javascript_finished, NULL); }
static void changed (WebKitWebView *view, WebKitLoadEvent event, gpointer data) { g_print ("%d ", event); if (!launched && event == WEBKIT_LOAD_FINISHED) { launched = TRUE; gchar *json = read_json (); if (!json) return; gchar *script = g_strdup_printf ("window.init_online(%s);", json); g_free (json); webkit_web_view_run_javascript (view, script, NULL, js_cb, NULL); g_free (script); } }
static void run_capture_javascript(WebKitWebView *web_view) { gchar script[2000]; gchar *file_name = "script/request_capture.js"; FILE *script_file = fopen(file_name, "r"); int res; if (script_file != NULL) { res = fread(script, 1, 2000, script_file); g_printf("Read %u bytes.\n", res); fclose(script_file); } else { g_printf("File not found: %s\n", file_name); } webkit_web_view_run_javascript(web_view, script, NULL, get_javascript_result, NULL); }
static void night_mode_tabs_view_notify_uri_cb (MidoriView* view, GParamSpec* pspec, MidoriExtension* extension) { gchar* exception = NULL; gchar *script=NULL; FILE *fp; int file_size; gboolean result; const gchar* uri = midori_view_get_display_uri (view); if (!*uri) return; if (g_night_mode) { if (!midori_uri_is_blank (uri)) { gchar* hostname = midori_uri_parse_hostname (uri, NULL); if (hostname) { if((fp=fopen(midori_paths_get_res_filename("night_mode/nightingale_view_content.js"),"r"))!=NULL) { fseek(fp,0,SEEK_END); file_size=ftell(fp); fseek(fp,0,SEEK_SET); script=(char *)malloc(file_size * sizeof(char)+1); fread(script,file_size,sizeof(char),fp); script[file_size*sizeof(char)]='\0'; fclose(fp); result = midori_view_execute_script (view, script, &exception); free(script); script=NULL; } g_free (hostname); } } } else { GtkWidget* current_web_view = midori_view_get_web_view (MIDORI_VIEW (view)); webkit_web_view_run_javascript(WEBKIT_WEB_VIEW (current_web_view), night_mode_remove, NULL, NULL, NULL); } }
static void night_mode_deactivated_cb (MidoriExtension* extension, MidoriBrowser* browser) { if(night_mode_button) gtk_widget_destroy (night_mode_button); g_signal_handlers_disconnect_by_func (extension, night_mode_deactivated_cb, browser); if(g_night_mode) { GList* children = midori_browser_get_tabs (MIDORI_BROWSER (browser)); for (; children; children = g_list_next (children)) { GtkWidget* current_web_view = midori_view_get_web_view (MIDORI_VIEW (children->data)); webkit_web_view_run_javascript(WEBKIT_WEB_VIEW (current_web_view), night_mode_remove, NULL, NULL, NULL); } g_list_free (children); g_signal_handlers_disconnect_by_func (browser, night_mode_extension_browser_add_tab_cb, NULL); } }
static void web_view_load_changed(WebKitWebView *web_view, WebKitLoadEvent load_event, gpointer user_data) { switch (load_event) { case WEBKIT_LOAD_STARTED: /* New load, we have now a provisional URI */ printf("%s: load start\n", webkit_web_view_get_uri(web_view)); /* Here we could start a spinner or update the * location bar with the provisional URI */ break; case WEBKIT_LOAD_REDIRECTED: printf("%s: redirect\n", webkit_web_view_get_uri(web_view)); break; case WEBKIT_LOAD_COMMITTED: /* The load is being performed. Current URI is * the final one and it won't change unless a new * load is requested or a navigation within the * same page is performed */ printf("%s: commit\n", webkit_web_view_get_uri(web_view)); break; case WEBKIT_LOAD_FINISHED: printf("%s: finished\n", webkit_web_view_get_uri(web_view)); /* Load finished, we can now stop the spinner */ webkit_web_view_get_snapshot(web_view, WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE, NULL, get_snapshot_finish, web_view ); gchar *script; script = get_jsfile(config->jsfile); //const gchar *script = "JSON.stringify(window.performance.timing)"; //script = "console.log('@#@#@#----console-')"; webkit_web_view_run_javascript(web_view, script, NULL, web_view_javascript_finished, NULL); free(script); break; } }
gboolean onKeyPress(GtkWidget *widget, GdkEventKey *key, RuskWindow *rusk) { gboolean proceed = TRUE; char *script = g_strdup_printf( "onKeyPress({ctrlKey: %d, shiftKey: %d, superKey: %d, hyperKey: %d, metaKey: %d, string: '%s'})", (key->state & GDK_CONTROL_MASK)?1:0, (key->state & GDK_SHIFT_MASK)?1:0, (key->state & GDK_SUPER_MASK)?1:0, (key->state & GDK_HYPER_MASK)?1:0, (key->state & GDK_META_MASK)?1:0, gdk_keyval_name(key->keyval)); webkit_web_view_run_javascript(rusk->webview, script, NULL, NULL, NULL); g_free(script); if(key->state & GDK_CONTROL_MASK) { switch(gdk_keyval_to_upper(key->keyval)) { case GDK_KEY_S: inSiteSearchToggle(rusk); break; case GDK_KEY_N: if(key->state & GDK_SHIFT_MASK) { openURI(createNewWindow(rusk), HOMEPAGE); }else { inSiteSearchNext(rusk); } break; case GDK_KEY_P: if(key->state & GDK_SHIFT_MASK) { togglePrivateBrowsing(rusk); }else { inSiteSearchPrev(rusk); } break; case GDK_KEY_U: addressbarToggle(rusk); break; case GDK_KEY_G: globalSearchToggle(rusk, "google"); break; case GDK_KEY_M: globalSearchToggle(rusk, "maps"); break; case GDK_KEY_I: if(key->state & GDK_SHIFT_MASK) { toggleInspector(rusk); }else { globalSearchToggle(rusk, "images"); } break; default: proceed = FALSE; } }else { proceed = FALSE; } return proceed; }