topcube-0.2.0/0000755000175000017500000000000012232712017011265 5ustar devdevtopcube-0.2.0/wscript0000644000175000017500000000144012224112266012703 0ustar devdevimport Options from os import unlink, symlink, popen from os.path import exists srcdir = "." blddir = "build" VERSION = "0.0.1" def set_options(opt): opt.tool_options("compiler_cxx") def configure(conf): conf.check_tool("compiler_cxx") conf.check_cfg(package='gtk+-2.0', uselib_store='GTK', args='--cflags --libs') conf.check_cfg(package='glib-2.0', args='--cflags --libs', uselib_store='GLIB') conf.check_cfg(package='webkit-1.0', args='--cflags --libs', uselib_store='WEBKIT') def build(bld): obj = bld.new_task_gen("cxx", "program") obj.target = "topcube" obj.source = "topcube.cpp" obj.cxxflags = ["-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE"] obj.uselib = "GTK GLIB WEBKIT" def shutdown(): if Options.commands['clean']: if exists('topcube'): unlink('topcube') topcube-0.2.0/lib/0000755000175000017500000000000012224112266012034 5ustar devdevtopcube-0.2.0/lib/topcube.js0000644000175000017500000000217612224112266014041 0ustar devdevvar spawn = require('child_process').spawn; var path = require('path'); module.exports = function (options) { options = options || {}; options.url = options.url || 'http://nodejs.org'; options.name = options.name || 'nodejs'; var client; var keys = []; switch (process.platform) { case 'win32': client = path.resolve(__dirname + '/../bin/cefclient/cefclient'); keys = ['url', 'name', 'width', 'height', 'minwidth', 'minheight', 'ico', 'cache-path', 'log-file']; break; case 'linux': client = path.resolve(__dirname + '/../bin/topcube'); keys = ['url', 'name', 'width', 'height', 'minwidth', 'minheight']; break; default: console.warn(''); return null; break; } var args = []; for (var key in options) { if (keys.indexOf(key) !== -1) { args.push('--' + key + '=' + options[key]); } } var child = spawn(client, args); child.on('exit', function(code) { process.exit(code); }); child.stdout.pipe(process.stdout); child.stderr.pipe(process.stderr); return child; }; topcube-0.2.0/lib/index.js0000644000175000017500000000004612224112266013501 0ustar devdevmodule.exports = require('./topcube');topcube-0.2.0/configure0000755000175000017500000000003412224112266013172 0ustar devdev#!/bin/sh node-waf configuretopcube-0.2.0/LICENSE0000644000175000017500000000207212224112266012274 0ustar devdevCopyright (c) 2011-2012 Tim Caswell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. topcube-0.2.0/src/0000755000175000017500000000000012224112266012055 5ustar devdevtopcube-0.2.0/src/topcube.cpp0000644000175000017500000001162012224112266014222 0ustar devdev#ifdef __APPLE__ #include int main(int argc, char* argv[]) { std::clog << "OS X is not currently supported by topcube\n"; return 0; } #else #include // for strcmp #include // for exit #include #include #include GtkWidget *window; GtkWidget *scrolled_window; GtkWidget *web_view; WebKitWebSettings *settings; void destroy (void) { gtk_main_quit (); } void title_change (void) { gtk_window_set_title(GTK_WINDOW (window), webkit_web_view_get_title(WEBKIT_WEB_VIEW (web_view))); } void new_window ( WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request) { gchar *argv[3]; argv[0] = const_cast("/usr/bin/xdg-open"); argv[1] = const_cast(webkit_network_request_get_uri(request)); argv[2] = NULL; g_spawn_async(NULL, argv, NULL, G_SPAWN_LEAVE_DESCRIPTORS_OPEN, NULL, NULL, NULL, NULL); } static gboolean download ( WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, const char *mime_type, WebKitWebPolicyDecision *decision, gpointer user_data) { // Any other mime types we should handle? if (strcmp(mime_type, "text/html") != 0) { WebKitDownload *download = webkit_download_new(request); GtkWidget *window = gtk_widget_get_toplevel (GTK_WIDGET(web_view)); GtkWidget *dialog = gtk_file_chooser_dialog_new ("Save file", GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), webkit_download_get_suggested_filename(download)); // @TODO getting a warning 'Unable to retrieve the file info' for the // file as it does not exist yet... track down why? if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { gchar *destination = g_filename_to_uri(gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)), NULL, NULL); webkit_download_set_destination_uri (download, destination); webkit_download_start(download); g_free(destination); } else { webkit_download_cancel(download); g_object_unref(download); } gtk_widget_destroy (dialog); webkit_web_policy_decision_ignore(decision); } return TRUE; } int main(int argc, char* argv[]) { static gchar *url = const_cast("http://google.com"); static gchar *name = const_cast("TopCube"); static gint width = 800; static gint height = 600; static gint minwidth = 600; static gint minheight = 400; static GOptionEntry entries[] = { { "url", 'u', 0, G_OPTION_ARG_STRING, &url, "URL", NULL }, { "name", 'n', 0, G_OPTION_ARG_STRING, &name, "Window name", NULL }, { "width", 'W', 0, G_OPTION_ARG_INT, &width, "Width", NULL }, { "height", 'H', 0, G_OPTION_ARG_INT, &height, "Height", NULL }, { "minwidth", 'w', 0, G_OPTION_ARG_INT, &minwidth, "Minimum width", NULL }, { "minheight", 'h', 0, G_OPTION_ARG_INT, &minheight, "Minimum height", NULL } }; GError *error = NULL; GOptionContext *options; options = g_option_context_new("topcube options"); g_option_context_add_main_entries (options, entries, NULL); g_option_context_add_group (options, gtk_get_option_group(TRUE)); if (!g_option_context_parse (options, &argc, &argv, &error)) { g_print ("Error parsing options: %s\n", error->message); exit (1); } gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); scrolled_window = gtk_scrolled_window_new (NULL, NULL); web_view = webkit_web_view_new (); // Modify default settings - disable right click menus. settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW(web_view)); g_object_set(settings, "enable-default-context-menu", FALSE, NULL); gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (destroy), NULL); gtk_signal_connect (GTK_OBJECT (web_view), "title-changed", GTK_SIGNAL_FUNC (title_change), NULL); gtk_signal_connect (GTK_OBJECT (web_view), "mime-type-policy-decision-requested", GTK_SIGNAL_FUNC (download), NULL); gtk_signal_connect (GTK_OBJECT (web_view), "new-window-policy-decision-requested", GTK_SIGNAL_FUNC (new_window), NULL); gtk_container_add (GTK_CONTAINER (scrolled_window), web_view); gtk_container_add (GTK_CONTAINER (window), scrolled_window); webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), url); gtk_window_set_wmclass (GTK_WINDOW (window), name, name); gtk_window_set_default_size (GTK_WINDOW (window), width, height); GdkGeometry hints; hints.min_width = minwidth; hints.min_height = minheight; gtk_window_set_geometry_hints(GTK_WINDOW (window), GTK_WIDGET (scrolled_window), &hints, GDK_HINT_MIN_SIZE); gtk_widget_grab_focus (GTK_WIDGET(web_view)); gtk_widget_show_all (window); gtk_main (); return 0; } #endif // linux topcube-0.2.0/binding.gyp0000644000175000017500000000236512224112266013427 0ustar devdev{ 'targets': [ { 'target_name': 'topcube', 'type': 'executable', 'conditions': [ ['OS!="win"', { 'sources': [ 'src/topcube.cpp' ], }], ['OS=="win"', { 'dependencies': [ 'deps/fetch-win-binary.gyp:download_cef' ], }], ['OS=="linux"', { 'cflags_cc' : [ '", "name": "topcube", "description": "Simple bindings to create a webkit window that node can control", "version": "0.2.0", "repository": { "type": "git", "url": "git://github.com/creationix/topcube.git" }, "main": "./lib/topcube.js", "dependencies": {}, "devDependencies": {}, "engines": { "node": ">= 0.8.11 < 0.11.0" } }