gboolean initdownload(WebKitWebView *view, WebKitDownload *o, Client *c) { const char *filename; char *uri, *html; stop(c, NULL); c->download = o; filename = webkit_download_get_suggested_filename(o); if(!strcmp("", filename)) filename = "index.html"; uri = g_strconcat("file://", dldir, "/", filename, NULL); webkit_download_set_destination_uri(c->download, uri); c->progress = 0; g_free(uri); html = g_strdup_printf("Download <b>%s</b>...", filename); webkit_web_view_load_html_string(c->view, html, webkit_download_get_uri(c->download)); g_signal_connect(c->download, "notify::progress", G_CALLBACK(updatedownload), c); g_signal_connect(c->download, "notify::status", G_CALLBACK(updatedownload), c); webkit_download_start(c->download); c->title = copystr(&c->title, filename); update(c); g_free(html); return TRUE; }
void cmd_inject_html() { if(uzbl.behave.inject_html) { webkit_web_view_load_html_string (uzbl.gui.web_view, uzbl.behave.inject_html, NULL); } }
void loadfile(Client *c, const gchar *f) { GIOChannel *chan = NULL; GError *e = NULL; GString *code; gchar *line, *uri; Arg arg; if(strcmp(f, "-") == 0) { chan = g_io_channel_unix_new(STDIN_FILENO); if (chan) { code = g_string_new(""); while(g_io_channel_read_line(chan, &line, NULL, NULL, &e) == G_IO_STATUS_NORMAL) { g_string_append(code, line); g_free(line); } webkit_web_view_load_html_string(c->view, code->str, "file://."); g_io_channel_shutdown(chan, FALSE, NULL); g_string_free(code, TRUE); } arg.v = uri = g_strdup("stdin"); } else { arg.v = uri = g_strdup_printf("file://%s", f); loaduri(c, &arg); } c->title = copystr(&c->title, uri); update(c); g_free(uri); }
void loadfile(const Client *c, const gchar *f) { GIOChannel *chan = NULL; GError *e = NULL; GString *code = g_string_new(""); GString *uri = g_string_new(f); gchar *line; if(strcmp(f, "-") == 0) { chan = g_io_channel_unix_new(STDIN_FILENO); if (chan) { while(g_io_channel_read_line(chan, &line, NULL, NULL, &e) == G_IO_STATUS_NORMAL) { g_string_append(code, line); g_free(line); } webkit_web_view_load_html_string(c->view, code->str, NULL); g_io_channel_shutdown(chan, FALSE, NULL); } } else { g_string_prepend(uri, "file://"); loaduri(c, uri->str); } }
void html_clear(Html *html) { static const char *data = "<html><body bgcolor=\"white\"></body></html>"; g_return_if_fail(IS_HTML (html)); webkit_web_view_load_html_string(html->webview,data,"file:///"); }
static void phidias_items_classic_set_model (PhidiasItemsViewer *self, GtkTreeModel *items) { GtkTreeModel *sorter; PhidiasItemsClassic *item; item = PHIDIAS_ITEMS_CLASSIC (self); webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (item->priv->description), "", "file://"); sorter = gtk_tree_view_get_model (GTK_TREE_VIEW (item->priv->list)); if (sorter != NULL) g_object_unref (sorter); sorter = gtk_tree_model_sort_new_with_model (items); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sorter), ITEM_INFO_DATE, GTK_SORT_DESCENDING); gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sorter), ITEM_INFO_DATE, sort_items, NULL, NULL); gtk_tree_view_set_model (GTK_TREE_VIEW (item->priv->list), sorter); scroll_to_position (item); }
static void item_selected_cb (GtkTreeSelection *treeselection, PhidiasItemsClassic *item) { gchar *desc; gchar *is_read; GtkTreeModel *model; GtkTreeIter iter; GtkTreeIter original_iter; if (gtk_tree_selection_get_selected (treeselection, &model, &iter) == TRUE) { gtk_tree_model_get (model, &iter, ITEM_INFO_READ, &is_read, ITEM_INFO_DESCRIPTION, &desc, -1); webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (item->priv->description), desc, "file://"); if (strcmp (is_read, "false") == 0) { gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (model), &original_iter, &iter); g_signal_emit_by_name (item, "item-update-required", &original_iter, ITEM_INFO_READ, "true"); } g_free (is_read); g_free (desc); } }
static void impl_webkit_show_data( GncHtml* self, const gchar* data, int datalen ) { GncHtmlWebkitPrivate* priv; #if HAVE(WEBKIT_WEB_VIEW_LOAD_URI) #define TEMPLATE_REPORT_FILE_NAME "gnc-report-XXXXXX.html" int fd; gchar* uri; gchar *filename; #endif g_return_if_fail( self != NULL ); g_return_if_fail( GNC_IS_HTML_WEBKIT(self) ); ENTER( "datalen %d, data %20.20s", datalen, data ); priv = GNC_HTML_WEBKIT_GET_PRIVATE(self); #if HAVE(WEBKIT_WEB_VIEW_LOAD_URI) /* Export the HTML to a file and load the file URI. On Linux, this seems to get around some security problems (otherwise, it can complain that embedded images aren't permitted to be viewed because they are local resources). On Windows, this allows the embedded images to be viewed (maybe for the same reason as on Linux, but I haven't found where it puts those messages. */ filename = g_build_filename(g_get_tmp_dir(), TEMPLATE_REPORT_FILE_NAME, (gchar *)NULL); fd = g_mkstemp( filename ); impl_webkit_export_to_file( self, filename ); close( fd ); uri = g_strdup_printf( "file:///%s", filename ); g_free(filename); DEBUG("Loading uri '%s'", uri); webkit_web_view_load_uri( priv->web_view, uri ); g_free( uri ); #else webkit_web_view_load_html_string( priv->web_view, data, BASE_URI_NAME ); #endif LEAVE(""); }
static void test_webkit_web_view_does_not_steal_focus() { loop = g_main_loop_new(NULL, TRUE); GtkWidget *window = gtk_offscreen_window_new(); GtkWidget *webView = webkit_web_view_new(); GtkWidget *entry = gtk_entry_new(); #ifdef GTK_API_VERSION_2 GtkWidget *box = gtk_hbox_new(FALSE, 0); #else GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); #endif gtk_container_add(GTK_CONTAINER(box), webView); gtk_container_add(GTK_CONTAINER(box), entry); gtk_container_add(GTK_CONTAINER(window), box); gtk_widget_show_all(window); gtk_widget_grab_focus(entry); g_assert(gtk_widget_is_focus(entry)); g_signal_connect(webView, "notify::load-status", G_CALLBACK(idle_quit_loop_cb), NULL); webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(webView), "<html><body>" " <input id=\"entry\" type=\"text\"/>" " <script>" " document.getElementById(\"entry\").focus();" " </script>" "</body></html>", "file://"); g_main_loop_run(loop); g_assert(gtk_widget_is_focus(entry)); gtk_widget_destroy(window); g_main_loop_unref(loop); }
static void load_to_stream( GncHtmlWebkit* self, URLType type, const gchar* location, const gchar* label ) { gchar* fdata = NULL; int fdata_len = 0; GncHtmlWebkitPrivate* priv = GNC_HTML_WEBKIT_GET_PRIVATE(self); DEBUG( "type %s, location %s, label %s", type ? type : "(null)", location ? location : "(null)", label ? label : "(null)"); g_return_if_fail( self != NULL ); if ( gnc_html_stream_handlers != NULL ) { GncHTMLStreamCB stream_handler; stream_handler = g_hash_table_lookup( gnc_html_stream_handlers, type ); if ( stream_handler ) { gboolean ok = stream_handler( location, &fdata, &fdata_len ); if ( ok ) { fdata = fdata ? fdata : g_strdup( "" ); // Until webkitgtk supports download requests, look for "<object classid=" // indicating the beginning of an embedded graph. If found, handle it if ( g_strstr_len( fdata, -1, "<object classid=" ) != NULL ) { gchar* new_fdata; new_fdata = handle_embedded_object( self, fdata ); g_free( fdata ); fdata = new_fdata; } // Save a copy for export purposes if ( priv->html_string != NULL ) { g_free( priv->html_string ); } priv->html_string = g_strdup( fdata ); impl_webkit_show_data( GNC_HTML(self), fdata, strlen(fdata) ); // webkit_web_view_load_html_string( priv->web_view, fdata, BASE_URI_NAME ); } else { fdata = fdata ? fdata : g_strdup_printf( error_404_format, _(error_404_title), _(error_404_body) ); webkit_web_view_load_html_string( priv->web_view, fdata, BASE_URI_NAME ); } g_free( fdata ); if ( label ) { while ( gtk_events_pending() ) { gtk_main_iteration(); } /* No action required: Webkit jumps to the anchor on its own. */ } return; } } do { if ( !g_strcmp0( type, URL_TYPE_SECURE ) || !g_strcmp0( type, URL_TYPE_HTTP ) ) { if ( !g_strcmp0( type, URL_TYPE_SECURE ) ) { if ( !https_allowed() ) { gnc_error_dialog( priv->base.parent, "%s", _("Secure HTTP access is disabled. " "You can enable it in the Network section of " "the Preferences dialog.")); break; } } if ( !http_allowed() ) { gnc_error_dialog( priv->base.parent, "%s", _("Network HTTP access is disabled. " "You can enable it in the Network section of " "the Preferences dialog.")); } else { gnc_build_url( type, location, label ); } } else { PWARN( "load_to_stream for inappropriate type\n" "\turl = '%s#%s'\n", location ? location : "(null)", label ? label : "(null)" ); fdata = g_strdup_printf( error_404_format, _(error_404_title), _(error_404_body) ); webkit_web_view_load_html_string( priv->web_view, fdata, BASE_URI_NAME ); g_free( fdata ); } } while ( FALSE ); }