コード例 #1
0
ファイル: interpreter.cpp プロジェクト: farnyser/haku
	/**
		\brief Save the content of the current page.
		\param app Pointer to the application object (or NULL).
		\param w Pointer to the current window object (or NULL).
		\param context Execution context.
		\param arg List of arguments.
		\return return_void on success.
		\return return_error if there is no window or the argument list is badly formed.
	**/
	int save(application *app, app_window *w, const exec_context context, std::vector<std::string> arg)
	{
		unsigned arg_size = arg.size();
		std::string cmd = haku::string::implode(arg,' ');
		
		if ( w == NULL && arg_size >= 2 )
		{
			WebKitNetworkRequest *r = webkit_network_request_new(arg[1].c_str());			
			
			w = app->create_window();
			w->download = webkit_download_new(r);
			w->osl = (context == exec_context_callback);
			
			if ( arg_size >= 3 )
				webkit_download_set_destination_uri(w->download, haku::string::trim(cmd.substr(arg[0].size()+2+arg[1].size(), -1)).c_str());
			
			app_window::initdownload(NULL, w->download, w);
			
			return return_void;
		}
		else if ( w != NULL )
		{
			WebKitNetworkRequest *r = webkit_network_request_new(w->geturi().c_str());			
			WebKitDownload *o = webkit_download_new(r);
			
			if ( arg_size >= 2 )
				webkit_download_set_destination_uri(o, haku::string::trim(cmd.substr(arg[0].size(), -1)).c_str());
			
			app_window::initdownload(NULL, o, w);
			
			return return_void;
		}
		
		return return_error;
	}
コード例 #2
0
ファイル: ephy-download.c プロジェクト: jdapena/epiphany
/**
 * ephy_download_new_for_uri:
 * @uri: a source URI from where to download
 *
 * Creates an #EphyDownload to download @uri.
 *
 * Returns: an #EphyDownload.
 **/
EphyDownload *
ephy_download_new_for_uri (const char *uri)
{
  EphyDownload *ephy_download;
  WebKitDownload *download;
#ifndef HAVE_WEBKIT2
  WebKitNetworkRequest *request;
#endif

  g_return_val_if_fail (uri != NULL, NULL);

#ifdef HAVE_WEBKIT2
  download = webkit_web_context_download_uri (webkit_web_context_get_default (), uri);
#else
  request = webkit_network_request_new (uri);
  download = webkit_download_new (request);

  g_return_val_if_fail (download != NULL, NULL);
  g_object_unref (request);
#endif

  ephy_download = ephy_download_new_for_download (download);
  g_object_unref (download);

  return ephy_download;
}
コード例 #3
0
ファイル: testdownload.c プロジェクト: jackiekaon/owb-mirror
static void
test_webkit_download_create(void)
{
    WebKitNetworkRequest* request;
    WebKitDownload* download;
    const gchar* uri = "http://example.com";
    gchar* tmpDir;

    request = webkit_network_request_new(uri);
    download = webkit_download_new(request);
    g_object_unref(request);
    g_assert_cmpstr(webkit_download_get_uri(download), ==, uri);
    g_assert(webkit_download_get_network_request(download) == request);
    g_assert(g_strrstr(uri, webkit_download_get_suggested_filename(download)));
    g_assert(webkit_download_get_status(download) == WEBKIT_DOWNLOAD_STATUS_CREATED);
    g_assert(!webkit_download_get_total_size(download));
    g_assert(!webkit_download_get_current_size(download));
    g_assert(!webkit_download_get_progress(download));
    g_assert(!webkit_download_get_elapsed_time(download));
    tmpDir = g_filename_to_uri(g_get_tmp_dir(), NULL, NULL);
    webkit_download_set_destination_uri(download, tmpDir);
    g_assert_cmpstr(tmpDir, ==, webkit_download_get_destination_uri(download));;
    g_free(tmpDir);
    g_object_unref(download);
}
コード例 #4
0
ファイル: webkit.c プロジェクト: rubiojr/gtk-webkit-ruby
static VALUE
Download_initialize(VALUE self, VALUE __v_request)
{
  WebKitNetworkRequest * request; WebKitNetworkRequest * __orig_request;
  __orig_request = request = RVAL2GOBJ(__v_request);

#line 224 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr"
  RBGTK_INITIALIZE(self, webkit_download_new(request));
 
  return Qnil;
}
コード例 #5
0
ファイル: download.c プロジェクト: DeforaOS/Surfer
/* download_on_idle */
static gboolean _download_on_idle(gpointer data)
{
    Download * download = data;
    DownloadPrefs * prefs = &download->prefs;
#ifdef WITH_WEBKIT
    char * p = NULL;
    char * cwd = NULL;
    size_t len;
    WebKitNetworkRequest * request;

    download->timeout = 0;
    if(prefs->output[0] != '/' && (cwd = getcwd(NULL, 0)) == NULL)
    {
        _download_error(download, prefs->output, 0);
        download_cancel(download);
        return FALSE;
    }
    len = ((cwd != NULL) ? strlen(cwd) : 0) + strlen(prefs->output) + 7;
    if((p = malloc(len)) == NULL)
    {
        _download_error(download, prefs->output, 0);
        download_cancel(download);
        free(cwd);
        return FALSE;
    }
    snprintf(p, len, "%s%s%s%s", "file:", (cwd != NULL) ? cwd : "",
             (cwd != NULL) ? "/" : "", prefs->output);
    request = webkit_network_request_new(download->url);
    download->conn = webkit_download_new(request);
    webkit_download_set_destination_uri(download->conn, p);
    free(p);
    free(cwd);
    webkit_download_start(download->conn);
#else
    download->timeout = 0;
    if((download->fp = fopen(prefs->output, "w")) == NULL)
    {
        _download_error(download, prefs->output, 0);
        download_cancel(download);
        return FALSE;
    }
    download->conn = gnet_conn_http_new();
    if(gnet_conn_http_set_method(download->conn, GNET_CONN_HTTP_METHOD_GET,
                                 NULL, 0) != TRUE)
        return _download_error(download, _("Unknown error"), FALSE);
    gnet_conn_http_set_uri(download->conn, download->url);
    if(prefs->user_agent != NULL)
        gnet_conn_http_set_user_agent(download->conn,
                                      prefs->user_agent);
    gnet_conn_http_run_async(download->conn, _download_on_http, download);
#endif
    download->timeout = g_timeout_add(250, _download_on_timeout, download);
    return FALSE;
}
コード例 #6
0
ファイル: surf.c プロジェクト: sr/surf-mirror
void
download(Client *c, const Arg *arg) {
	char *uri;
	WebKitNetworkRequest *r;
	WebKitDownload       *dl;

	if(arg->v)
		uri = (char *)arg->v;
	else
		uri = c->linkhover ? c->linkhover : geturi(c);
	r = webkit_network_request_new(uri);
	dl = webkit_download_new(r);
	initdownload(c->view, dl, c);
}
コード例 #7
0
ファイル: download.c プロジェクト: Alexis-D/luakit
/**
 * Creates a new download on the stack.
 *
 * \param L The Lua VM state.
 *
 * \luastack
 * \lvalue A table containing properties to set on the download.
 * \lreturn A new \c download object.
 */
static gint
luaH_download_new(lua_State *L)
{
    luaH_class_new(L, &download_class);
    download_t *download = luaH_checkdownload(L, -1);

    /* create download from constructor properties */
    WebKitNetworkRequest *request = webkit_network_request_new(
            download->uri);
    download->webkit_download = webkit_download_new(request);
    g_object_ref(G_OBJECT(download->webkit_download));

    /* raise error signal on error */
    g_signal_connect(G_OBJECT(download->webkit_download), "error",
            G_CALLBACK(error_cb), download);

    /* return download */
    return 1;
}
コード例 #8
0
ファイル: command.c プロジェクト: dantleech/vimb
gboolean command_save(const Arg *arg)
{
    WebKitDownload *download;
    const char *uri, *path = NULL;

    if (arg->i == COMMAND_SAVE_CURRENT) {
        uri = vb.state.uri;
        /* given string is the path to save the download to */
        if (arg->s && *(arg->s) != '\0') {
            path = arg->s;
        }
    } else {
        uri = arg->s;
    }

    if (!uri || !*uri) {
        return false;
    }

    download = webkit_download_new(webkit_network_request_new(uri));
    vb_download(vb.gui.webview, download, path);

    return true;
}