Пример #1
0
int
main (int argc, char* argv[]) {
    const char *uri;
    WebKitWebView* web_view;
    GMainLoop* loop;
    SoupSession *session;

    gtk_init(&argc, &argv);
  
    if (argc == 1) {
        printf("Usage: URI\n");
        return 1;
    }
    uri = argv[1];

    if (!g_thread_supported()) {g_thread_init(NULL);}

    loop = g_main_loop_new(NULL, TRUE);

    session = webkit_get_default_session();
    g_signal_connect(session, "request-started", G_CALLBACK(request_started_cb), NULL);

    web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
    g_object_ref_sink(G_OBJECT(web_view));

    g_signal_connect(web_view, "notify::load-status", G_CALLBACK(load_status_cb), loop);
    webkit_web_view_load_uri(web_view, uri);

    g_main_loop_run(loop);

    g_object_unref(web_view);

    return 0;
}
Пример #2
0
void ripcurl_init(void)
{
	/* webkit settings */
	ripcurl->Global.webkit_settings = webkit_web_settings_new();

	/* libsoup session */
	ripcurl->Global.soup_session = webkit_get_default_session();

	/* browser list */
	ripcurl->Global.browsers = NULL;

	/* bookmarks list */
	ripcurl->Global.bookmarks = NULL;

	/* history list */
	ripcurl->Global.history = NULL;

	/* command history list */
	ripcurl->Global.command_history = NULL;

	/* GDK keymap */
	ripcurl->Global.keymap = gdk_keymap_get_default();

	/* create config dir */
	ripcurl->Files.config_dir = g_build_filename(g_get_user_config_dir(), "ripcurl", NULL);
	g_mkdir_with_parents(ripcurl->Files.config_dir, 0771);
}
Пример #3
0
void LayoutTestController::setAlwaysAcceptCookies(bool alwaysAcceptCookies)
{
#ifdef HAVE_LIBSOUP_2_29_90
    SoupSession* session = webkit_get_default_session();
    SoupCookieJar* jar = reinterpret_cast<SoupCookieJar*>(soup_session_get_feature(session, SOUP_TYPE_COOKIE_JAR));

    /* If the jar was not created - we create it on demand, i.e, just
       in case we have HTTP requests - then we must create it here in
       order to set the proper accept policy */
    if (!jar) {
        jar = soup_cookie_jar_new();
        soup_session_add_feature(session, SOUP_SESSION_FEATURE(jar));
        g_object_unref(jar);
    }

    SoupCookieJarAcceptPolicy policy;

    if (alwaysAcceptCookies)
        policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
    else
        policy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;

    g_object_set(G_OBJECT(jar), SOUP_COOKIE_JAR_ACCEPT_POLICY, policy, NULL);
#endif
}
Пример #4
0
OssiferSession *
ossifer_session_initialize (const gchar *cookie_db_path,
    OssiferSessionCookieJarChanged cookie_jar_changed_callback)
{
    static OssiferSession *session_instance = NULL;

    SoupSession *session;
    SoupCookieJar *cookie_jar;
    gchar *path;

    if (session_instance != NULL) {
        return session_instance;
    }

    session_instance = g_new0 (OssiferSession, 1);
    session_instance->cookie_jar_changed = cookie_jar_changed_callback;

    session = webkit_get_default_session ();

    g_object_set (session,
                  SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE,
                  NULL);

    path = g_strdup_printf ("%s.sqlite", cookie_db_path);
    cookie_jar = soup_cookie_jar_db_new (path, FALSE);
    soup_session_add_feature (session, SOUP_SESSION_FEATURE (cookie_jar));
    g_object_unref (cookie_jar);
    g_free (path);

    g_signal_connect (cookie_jar, "changed",
        G_CALLBACK (ossifer_session_cookie_jar_changed),
        session_instance);

    return session_instance;
}
Пример #5
0
/* ghtml_set_proxy */
int ghtml_set_proxy(GtkWidget * widget, SurferProxyType type, char const * http,
		unsigned int http_port)
{
#if WEBKIT_CHECK_VERSION(1, 1, 0)
	SoupSession * session;
	char buf[32];
	struct hostent * he;
	struct in_addr addr;
	SoupURI * uri = NULL;

	session = webkit_get_default_session();
	if(type == SPT_HTTP && http != NULL && strlen(http) > 0)
	{
		if((he = gethostbyname(http)) == NULL)
			return -error_set_code(1, "%s: %s", http, hstrerror(
						h_errno));
		memcpy(&addr.s_addr, he->h_addr, sizeof(addr.s_addr));
		snprintf(buf, sizeof(buf), "http://%s:%u/", inet_ntoa(addr),
				http_port);
		uri = soup_uri_new(buf);
	}
	g_object_set(session, "proxy-uri", uri, NULL);
	return 0;
#else
	/* FIXME really implement */
	return -error_set_code(1, "%s", strerror(ENOSYS));
#endif
}
Пример #6
0
Файл: surf.c Проект: sr/surf
int main(int argc, char *argv[]) {
    gchar *uri = NULL, *file = NULL;
    SoupSession *s;
    Client *c;
    int o;
    const gchar *home, *filename;

    gtk_init(NULL, NULL);
    if (!g_thread_supported())
        g_thread_init(NULL);
    setup();
    while((o = getopt(argc, argv, "vhxeu:f:")) != -1)
        switch(o) {
        case 'x':
            showxid = TRUE;
            break;
        case 'e':
            showxid = TRUE;
            embed = TRUE;
            break;
        case 'u':
            if(!(uri = optarg))
                goto argerr;
            c = newclient();
            loaduri(c, uri);
            updatetitle(c);
            break;
        case 'f':
            if(!(file = optarg))
                goto argerr;
            c = newclient();
            loadfile(c, file);
            updatetitle(c);
            break;
        case 'v':
            die("surf-"VERSION", © 2009 surf engineers, see LICENSE for details\n");
            break;
argerr:
        default:
            puts("surf - simple browser");
            die("usage: surf [-e] [-x] [-u uri] [-f file]\n");
            return EXIT_FAILURE;
        }
    if(optind != argc)
        goto argerr;
    if(!clients)
        newclient();

    /* cookie persistance */
    s = webkit_get_default_session();
    home = g_get_home_dir();
    filename = g_build_filename(home, ".surf-cookies", NULL);
    cookiejar = soup_cookie_jar_text_new(filename, FALSE);
    soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));

    gtk_main();
    cleanup();
    return EXIT_SUCCESS;
}
Пример #7
0
void
setup(void) {
	char *proxy;
	char *new_proxy;
	SoupURI *puri;
	SoupSession *s;

	/* clean up any zombies immediately */
	sigchld(0);
	gtk_init(NULL, NULL);
	if (!g_thread_supported())
		g_thread_init(NULL);

	dpy = GDK_DISPLAY();
	s = webkit_get_default_session();

	/* atoms */
	atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
	atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
	atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);

	/* dirs and files */
	cookiefile = buildpath(cookiefile);
	scriptfile = buildpath(scriptfile);
	stylefile = buildpath(stylefile);

	/* request handler */
	s = webkit_get_default_session();
	soup_session_remove_feature_by_type(s, soup_cookie_get_type());
	soup_session_remove_feature_by_type(s, soup_cookie_jar_get_type());
	g_signal_connect_after(G_OBJECT(s), "request-started", G_CALLBACK(newrequest), NULL);

	/* proxy */
	if((proxy = getenv("http_proxy")) && strcmp(proxy, "")) {
		new_proxy = g_strrstr(proxy, "http://") ? g_strdup(proxy) :
			g_strdup_printf("http://%s", proxy);
		puri = soup_uri_new(new_proxy);
		g_object_set(G_OBJECT(s), "proxy-uri", puri, NULL);
		soup_uri_free(puri);
		g_free(new_proxy);
	}


	XSetErrorHandler(&xerrorhandler);
}
Пример #8
0
JNIEXPORT jintLong JNICALL WebKitGTK_NATIVE(_1webkit_1get_1default_1session)
	(JNIEnv *env, jclass that)
{
	jintLong rc = 0;
	WebKitGTK_NATIVE_ENTER(env, that, _1webkit_1get_1default_1session_FUNC);
	rc = (jintLong)webkit_get_default_session();
	WebKitGTK_NATIVE_EXIT(env, that, _1webkit_1get_1default_1session_FUNC);
	return rc;
}
Пример #9
0
static SoupCookieJar *get_current_cookie_jar ()
{
  SoupSession *session = webkit_get_default_session ();
  SoupCookieJar *jar;

  jar = (SoupCookieJar*)soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR);

  /* WebKit might not have a cookie jar yet, if it has not needed one
   * and none has been set by Epiphany. */
  return jar ? g_object_ref (jar) : NULL;
}
Пример #10
0
void spike_setup_webkit_globals(char * web_database_path, char * cookie_jar_path)
{
  //eg. /tmp/spike.webkit.db
  webkit_set_web_database_directory_path(web_database_path);

  
  SoupSession * ses = webkit_get_default_session();
  //eg. /tmp/spike.webkit.cookie.db
  SoupCookieJar * jar = soup_cookie_jar_sqlite_new(cookie_jar_path, 0);
  soup_session_add_feature( ses, SOUP_SESSION_FEATURE (jar));
}
Пример #11
0
void
setup(void) {
	SoupSession *s;
	char *proxy;
	char *new_proxy;
	SoupURI *puri;

	/* clean up any zombies immediately */
	sigchld(0);
	gtk_init(NULL, NULL);
	if (!g_thread_supported())
		g_thread_init(NULL);

	dpy = GDK_DISPLAY();
	session = webkit_get_default_session();
	uriprop = XInternAtom(dpy, "_SURF_URI", False);
	findprop = XInternAtom(dpy, "_SURF_FIND", False);

	/* create dirs and files */
	cookiefile = buildpath(cookiefile);
	dldir = buildpath(dldir);
	scriptfile = buildpath(scriptfile);
	stylefile = buildpath(stylefile);

	/* cookie persistance */
	s = webkit_get_default_session();
	cookies = soup_cookie_jar_new();
	soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookies));
	g_signal_connect(cookies, "changed", G_CALLBACK(changecookie), NULL);
	if((proxy = getenv("http_proxy")) && strcmp(proxy, "")) {
		new_proxy = g_strrstr(proxy, "http://") ? g_strdup(proxy) :
			    g_strdup_printf("http://%s", proxy);

		puri = soup_uri_new(new_proxy);
		g_object_set(G_OBJECT(s), "proxy-uri", puri, NULL);
		soup_uri_free(puri);
		g_free(new_proxy);
	}
	reloadcookies();
}
Пример #12
0
OssiferSession *
ossifer_session_initialize (const gchar *cookie_db_path,
    OssiferSessionCookieJarChanged cookie_jar_changed_callback)
{
    static OssiferSession *session_instance = NULL;

    SoupSession *session;
    SoupCookieJar *cookie_jar;
    gchar *path;

    if (session_instance != NULL) {
        return session_instance;
    }

    session_instance = g_new0 (OssiferSession, 1);
    session_instance->cookie_jar_changed = cookie_jar_changed_callback;

    session = webkit_get_default_session ();

#ifdef HAVE_LIBSOUP_2_38
    g_object_set (session,
                  SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE,
                  NULL);
#endif

#ifdef HAVE_LIBSOUP_2_38
    g_object_set (session,
                  SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE,
                  NULL);
#endif

#ifdef HAVE_LIBSOUP_GNOME
    path = g_strdup_printf ("%s.sqlite", cookie_db_path);
    cookie_jar = soup_cookie_jar_sqlite_new (path, FALSE);
#else
    path = g_strdup_printf ("%s.txt", cookie_db_path);
    cookie_jar = soup_cookie_jar_text_new (path, FALSE);
#endif
    soup_session_add_feature (session, SOUP_SESSION_FEATURE (cookie_jar));
    g_object_unref (cookie_jar);
    g_free (path);

    g_signal_connect (cookie_jar, "changed",
        G_CALLBACK (ossifer_session_cookie_jar_changed),
        session_instance);

#ifdef HAVE_LIBSOUP_GNOME
    soup_session_add_feature_by_type (session, SOUP_TYPE_PROXY_RESOLVER_GNOME);
#endif

    return session_instance;
}
Пример #13
0
/* ghtml_set_user_agent */
int ghtml_set_user_agent(GtkWidget * ghtml, char const * user_agent)
{
#if WEBKIT_CHECK_VERSION(1, 1, 0)
	SoupSession * session;

	session = webkit_get_default_session();
	g_object_set(session, "user-agent", user_agent, NULL);
	return 0;
#else
	if(user_agent == NULL)
		return 0;
	return -error_set_code(1, "%s", strerror(ENOSYS));
#endif
}
Пример #14
0
widget_t *
widget_webview(widget_t *w)
{
    w->index = luaH_webview_index;
    w->newindex = luaH_webview_newindex;
    w->destructor = webview_destructor;

    /* init soup session & cookies handling */
    if (!Soup.session) {
        Soup.session = webkit_get_default_session();
        gchar *cookie_file = g_build_filename(globalconf.base_data_directory, "cookies.txt", NULL);
        Soup.cookiejar = soup_cookie_jar_text_new(cookie_file, FALSE);
        soup_session_add_feature(Soup.session, (SoupSessionFeature*) Soup.cookiejar);
        g_free(cookie_file);
    }

    GtkWidget *view = webkit_web_view_new();
    w->widget = gtk_scrolled_window_new(NULL, NULL);
    g_object_set_data(G_OBJECT(w->widget), "widget", w);
    g_object_set_data(G_OBJECT(w->widget), "webview", view);
    gtk_container_add(GTK_CONTAINER(w->widget), view);

    show_scrollbars(w, TRUE);

    /* connect webview signals */
    g_object_connect((GObject*)view,
      "signal::button-press-event",                   (GCallback)wv_button_press_cb,     w,
      "signal::expose-event",                         (GCallback)expose_cb,              w,
      "signal::focus-in-event",                       (GCallback)focus_cb,               w,
      "signal::focus-out-event",                      (GCallback)focus_cb,               w,
      "signal::hovering-over-link",                   (GCallback)link_hover_cb,          w,
      "signal::key-press-event",                      (GCallback)key_press_cb,           w,
      "signal::load-committed",                       (GCallback)load_commit_cb,         w,
      "signal::load-finished",                        (GCallback)load_finish_cb,         w,
      "signal::load-progress-changed",                (GCallback)progress_cb,            w,
      "signal::load-started",                         (GCallback)load_start_cb,          w,
      "signal::navigation-policy-decision-requested", (GCallback)navigation_decision_cb, w,
      "signal::parent-set",                           (GCallback)parent_set_cb,          w,
      "signal::title-changed",                        (GCallback)title_changed_cb,       w,
      "signal::download-requested",                   (GCallback)download_request_cb,    w,
      "signal::mime-type-policy-decision-requested",  (GCallback)mime_type_decision_cb,  w,
      NULL);

    /* setup */
    gtk_widget_show(view);
    gtk_widget_show(w->widget);

    return w;
}
Пример #15
0
int
main (int    argc,
      char** argv)
{
    midori_app_setup (argv);
    g_object_set_data (G_OBJECT (webkit_get_default_session ()),
                       "midori-session-initialized", (void*)1);
    g_test_init (&argc, &argv, NULL);
    gtk_init_check (&argc, &argv);

    g_test_add_func ("/browser/create", browser_create);
    g_test_add_func ("/browser/tooltips", browser_tooltips);

    return g_test_run ();
}
Пример #16
0
int main(int argc, char* argv[])
{
    WebKitWebView *webView;
    GtkWidget *main_window;

    gtk_init(&argc, &argv);
    if (!g_thread_supported())
        g_thread_init(NULL);

#ifndef WEBKIT2
#ifdef SOUP_TYPE_PROXY_RESOLVER_DEFAULT
    soup_session_add_feature_by_type(webkit_get_default_session(), SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
#else
    const char *httpProxy = g_getenv("http_proxy");
    if (httpProxy) {
        SoupURI *proxyUri = soup_uri_new(httpProxy);
        g_object_set(webkit_get_default_session(), SOUP_SESSION_PROXY_URI, proxyUri, NULL);
        soup_uri_free(proxyUri);
    }
#endif
#endif

    main_window = createWindow(&webView);

    gchar *uri =(gchar*)(argc > 1 ? argv[1] : "http://www.google.com/");
    gchar *fileURL = filenameToURL(uri);

    webkit_web_view_load_uri(webView, fileURL ? fileURL : uri);
    g_free(fileURL);

    gtk_widget_grab_focus(GTK_WIDGET(webView));
    gtk_widget_show_all(main_window);
    gtk_main();

    return 0;
}
Пример #17
0
GtkWidget *
html_create_widget (GtkWidget * dlg)
{
    GtkWidget *sw;
    WebKitWebSettings *settings;
    SoupSession *sess;
    const gchar *enc;

    sw = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

    view = WEBKIT_WEB_VIEW (webkit_web_view_new ());
    gtk_container_add (GTK_CONTAINER (sw), GTK_WIDGET (view));

    settings = webkit_web_view_get_settings (view);
    g_get_charset (&enc);
    g_object_set (G_OBJECT (settings), "default-encoding", enc);

    g_signal_connect (view, "hovering-over-link", G_CALLBACK (link_hover_cb), NULL);
    g_signal_connect (view, "navigation-policy-decision-requested", G_CALLBACK (link_cb), NULL);

    if (options.html_data.browser)
        g_signal_connect (view, "context-menu", G_CALLBACK (menu_cb), NULL);
    else
        g_signal_connect (view, "document-load-finished", G_CALLBACK (loaded_cb), NULL);

    sess = webkit_get_default_session ();
    soup_session_add_feature_by_type (sess, SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
    g_object_set (G_OBJECT (sess), SOUP_SESSION_ACCEPT_LANGUAGE_AUTO, TRUE, NULL);

    gtk_widget_show_all (sw);
    gtk_widget_grab_focus (GTK_WIDGET (view));

    if (options.html_data.uri)
        load_uri (options.html_data.uri);
    else if (!options.html_data.browser)
    {
        GIOChannel *ch;

        inbuf = g_string_new (NULL);
        ch = g_io_channel_unix_new (0);
        g_io_channel_set_encoding (ch, NULL, NULL);
        g_io_channel_set_flags (ch, G_IO_FLAG_NONBLOCK, NULL);
        g_io_add_watch (ch, G_IO_IN | G_IO_HUP, handle_stdin, NULL);
    }

    return sw;
}
Пример #18
0
/* Hide the authentication browser */
void
auth_browser_hide (AuthBrowser *browser)
{
    AuthBrowserPrivate *priv = GET_PRIVATE (browser);
    SoupSession *session = webkit_get_default_session ();
    SoupCookieJar* jar = (SoupCookieJar*)soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR);
    GSList *l, *p;

    gtk_widget_hide (priv->window);

    /* clear cookies */
    l = soup_cookie_jar_all_cookies (jar);
    for (p = l; p; p = p->next)
        soup_cookie_jar_delete_cookie (jar, (SoupCookie*)p->data);

    soup_cookies_free (l);
}
Пример #19
0
static void
liferea_webkit_set_proxy (const gchar *host, guint port, const gchar *user, const gchar *pwd)
{
	SoupURI *proxy = NULL;

	if (host) {
		proxy = soup_uri_new (NULL);
		soup_uri_set_scheme (proxy, SOUP_URI_SCHEME_HTTP);
		soup_uri_set_host (proxy, host);
		soup_uri_set_port (proxy, port);
		soup_uri_set_user (proxy, user);
		soup_uri_set_password (proxy, pwd);
	}

	g_object_set (webkit_get_default_session (),
		      SOUP_SESSION_PROXY_URI, proxy,
		      NULL);
}
Пример #20
0
static int _download_set_proxy(Download * download, char const * http,
                               uint16_t http_port)
{
#ifdef WITH_WEBKIT
# if WEBKIT_CHECK_VERSION(1, 1, 0)
    SoupSession * session;
    struct addrinfo hints;
    struct addrinfo * ai;
    struct addrinfo * aip;
    char buf[6];
    int res;
    SoupURI * uri = NULL;

    session = webkit_get_default_session();
    if(http != NULL && strlen(http) > 0)
    {
        snprintf(buf, sizeof(buf), "%hu", http_port);
        memset(&hints, 0, sizeof(hints));
        hints.ai_family = AF_UNSPEC;
        hints.ai_socktype = SOCK_STREAM;
        hints.ai_flags = AI_NUMERICSERV;
        if((res = getaddrinfo(http, buf, &hints, &ai)) != 0)
            return -error_set_code(1, "%s: %s", http, gai_strerror(
                                       res));
        for(aip = ai; aip != NULL; aip = aip->ai_next)
            if((uri = _set_proxy_address(aip)) != NULL)
                break;
        freeaddrinfo(ai);
        if(uri == NULL)
            return -error_set_code(1, "%s: %s", http,
                                   "No suitable address found for proxy");
    }
    g_object_set(session, "proxy-uri", uri, NULL);
    return 0;
# else
    /* FIXME really implement */
    return -error_set_code(1, "%s", strerror(ENOSYS));
# endif
#else
    /* FIXME really implement */
    return -error_set_code(1, "%s", strerror(ENOSYS));
#endif
}
Пример #21
0
static void _new_init(GHtml * ghtml)
{
	static int initialized = 0;
#if WEBKIT_CHECK_VERSION(1, 1, 0)
	SoupSession * session;
# if WEBKIT_CHECK_VERSION(1, 3, 5) && defined(EMBEDDED)
	WebKitWebSettings * settings;
# endif
	char const * cacerts[] =
	{
		"/etc/pki/tls/certs/ca-bundle.crt",
		"/etc/ssl/certs/ca-certificates.crt",
		"/etc/openssl/certs/ca-certificates.crt",
		PREFIX "/etc/ssl/certs/ca-certificates.crt",
		PREFIX "/etc/openssl/certs/ca-certificates.crt"
	};
	size_t i;
#endif

	if(initialized++ != 0)
	{
		initialized = 1;
		return;
	}
#if WEBKIT_CHECK_VERSION(1, 1, 0)
	session = webkit_get_default_session();
# if WEBKIT_CHECK_VERSION(1, 3, 5) && defined(EMBEDDED)
	settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(ghtml->view));
	g_object_set(settings, "enable-frame-flattening", TRUE, NULL);
# endif
	for(i = 0; i < sizeof(cacerts) / sizeof(*cacerts); i++)
		if(access(cacerts[i], R_OK) == 0)
		{
			g_object_set(session, "ssl-ca-file", cacerts[i],
					"ssl-strict", FALSE, NULL);
			ghtml->ssl = TRUE;
			return;
		}
#endif
	surfer_warning(ghtml->surfer, _("Could not load certificate bundle:\n"
			"SSL certificates will not be verified."));
}
Пример #22
0
/* Object initialization
 * Create private structure and set up default values
 */
static void cookie_permission_manager_init(CookiePermissionManager *self)
{
	CookiePermissionManagerPrivate	*priv;

	priv=self->priv=COOKIE_PERMISSION_MANAGER_GET_PRIVATE(self);

	/* Set up default values */
	priv->database=NULL;
	priv->databaseFilename=NULL;
	priv->unknownPolicy=COOKIE_PERMISSION_MANAGER_POLICY_UNDETERMINED;

	/* Hijack session's cookie jar to handle cookies requests on our own in HTTP streams
	 * but remember old handlers to restore them on deactivation
	 */
	priv->session=webkit_get_default_session();
	priv->cookieJar=SOUP_COOKIE_JAR(soup_session_get_feature(priv->session, SOUP_TYPE_COOKIE_JAR));
	priv->featureIface=SOUP_SESSION_FEATURE_GET_CLASS(priv->cookieJar);
	g_object_set_data(G_OBJECT(priv->cookieJar), "cookie-permission-manager", self);

	/* Listen to changed cookies set or changed by other sources like javascript */
	priv->cookieJarChangedID=g_signal_connect_swapped(priv->cookieJar, "changed", G_CALLBACK(_cookie_permission_manager_on_cookie_changed), self);
}
Пример #23
0
	GtkUIBinding::GtkUIBinding(Host *host) :
		UIBinding(host),
		menu(0),
		contextMenu(0),
		iconPath("")
	{
		// Prepare the custom URL handlers
		webkit_titanium_set_normalize_url_cb(NormalizeURLCallback);
		webkit_titanium_set_url_to_file_url_cb(URLToFileURLCallback);
		webkit_titanium_set_can_preprocess_cb(CanPreprocessURLCallback);
		webkit_titanium_set_preprocess_cb(PreprocessURLCallback);

		// Setup libsoup proxy support
		SoupSession* session = webkit_get_default_session();
		soup_session_add_feature_by_type(session, SOUP_TYPE_PROXY_RESOLVER_GNOME);

		std::string webInspectorPath(host->GetApplication()->runtime->path);
		webInspectorPath = FileUtils::Join(webInspectorPath.c_str(), "webinspector", NULL);
		webkit_titanium_set_inspector_url(webInspectorPath.c_str());

		//webkit_set_cache_model(WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
	}
Пример #24
0
/**
 * Sends a http-request synchronously
 * @name sendRequestSync
 * @memberOf net
 * @function
 *
 * @param {String} uri          The uri the request will be sent to.
 * @param {String} [method]     The http request method, default GET
 *
 * @returns {Object}
 *      Object that contains the response body, the response headers and the
 *      http status code of the request.
 * */
static JSValueRef
net_send_request_sync(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
    char *method = NULL, *uri = NULL;
    SoupMessage *msg;
    guint status;
    JSValueRef val;
    JSObjectRef o;
    JSStringRef js_key;
    JSValueRef js_value;

    if (argc < 1)
        return NIL;

    uri = js_value_to_char(ctx, argv[0], -1, exc);
    if (uri == NULL)
        return NIL;

    if (argc > 1)
        method = js_value_to_char(ctx, argv[1], -1, exc);

    msg = soup_message_new(method == NULL ? "GET" : method, uri);
    if (argc > 2)
        set_request(ctx, msg, argv[2], exc);

    status = soup_session_send_message(webkit_get_default_session(), msg);
    val = get_message_data(msg);

    js_key = JSStringCreateWithUTF8CString("status");
    js_value = JSValueMakeNumber(ctx, status);

    o = JSValueToObject(ctx, val, exc);
    JSObjectSetProperty(ctx, o, js_key, js_value, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, exc);

    JSStringRelease(js_key);
    return o;
}
Пример #25
0
/**
 * Sends a http-request
 * @name sendRequest
 * @memberOf net
 * @function
 *
 * @param {String} uri
 *      The uri the request will be sent to.
 * @param {net~onResponse} callback
 *      A callback that will be called when the request is finished
 * @param {String} [method]     The http request method, default GET
 * @param {Object} [data]       An object if method is POST
 * @param {String} data.contentType The content type
 * @param {String} data.data    The data that will be sent with the request
 *
 * @returns {Boolean}
 *      true if the request was sent
 * */
static JSValueRef
net_send_request(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
    gboolean ret = -1;
    char *method = NULL, *uri = NULL;
    SoupMessage *msg;
    JSObjectRef function;
    if (argc < 2)
        return JSValueMakeNumber(ctx, -1);

    uri = js_value_to_char(ctx, argv[0], -1, exc);
    if (uri == NULL)
        return JSValueMakeNumber(ctx, -1);

    function = js_value_to_function(ctx, argv[1], exc);
    if (function == NULL)
        goto error_out;

    if (argc > 2)
        method = js_value_to_char(ctx, argv[2], -1, exc);

    msg = soup_message_new(method == NULL ? "GET" : method, uri);
    if (msg == NULL)
        goto error_out;
    if (argc > 3 && method != NULL && !g_ascii_strcasecmp("POST", method))
        set_request(ctx, msg, argv[3], exc);

    JSValueProtect(ctx, function);
    soup_session_queue_message(webkit_get_default_session(), msg, (SoupSessionCallback)request_callback, function);
    ret = 0;

error_out:
    g_free(uri);
    g_free(method);
    return JSValueMakeNumber(ctx, ret);
}/*}}}*/
Пример #26
0
int main(int argc, char* argv[])
{
    WebKitWebSettings *webkitSettings = 0;
    const gchar **uriArguments = 0;
    const GOptionEntry commandLineOptions[] =
    {
        { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &uriArguments, 0, "[URL]" },
        { 0, 0, 0, 0, 0, 0, 0 }
    };

    gtk_init(&argc, &argv);

    GOptionContext *context = g_option_context_new(0);
    g_option_context_add_main_entries(context, commandLineOptions, 0);
    g_option_context_add_group(context, gtk_get_option_group(TRUE));

    webkitSettings = webkit_web_settings_new();
    if (!addWebSettingsGroupToContext(context, webkitSettings)) {
        g_object_unref(webkitSettings);
        webkitSettings = 0;
    }

    GError *error = 0;
    if (!g_option_context_parse(context, &argc, &argv, &error)) {
        g_printerr("Cannot parse arguments: %s\n", error->message);
        g_error_free(error);
        g_option_context_free(context);

        return 1;
    }
    g_option_context_free(context);

#ifdef SOUP_TYPE_PROXY_RESOLVER_DEFAULT
    soup_session_add_feature_by_type(webkit_get_default_session(), SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
#else
    const char *httpProxy = g_getenv("http_proxy");
    if (httpProxy) {
        SoupURI *proxyUri = soup_uri_new(httpProxy);
        g_object_set(webkit_get_default_session(), SOUP_SESSION_PROXY_URI, proxyUri, NULL);
        soup_uri_free(proxyUri);
    }
#endif

    WebKitWebView *webView;
    GtkWidget *main_window = createWindow(&webView);

    if (webkitSettings) {
        webkit_web_view_set_settings(WEBKIT_WEB_VIEW(webView), webkitSettings);
        g_object_unref(webkitSettings);
    }

    const gchar *uri = (uriArguments ? uriArguments[0] : "http://www.google.com/");
    gchar *fileURL = filenameToURL(uri);

    webkit_web_view_load_uri(webView, fileURL ? fileURL : uri);
    g_free(fileURL);

    gtk_widget_grab_focus(GTK_WIDGET(webView));
    gtk_widget_show_all(main_window);
    gtk_main();

    return 0;
}
Пример #27
0
static void add_cookie(char *cookie_file)
{
     SoupSession *session = webkit_get_default_session();
     SoupCookieJar *jar = soup_cookie_jar_text_new(cookie_file, false);
     soup_session_add_feature(session, SOUP_SESSION_FEATURE(jar));
}
Пример #28
0
static SoupCookieJar *
ossifer_session_get_cookie_jar ()
{
    return (SoupCookieJar *)soup_session_get_feature (webkit_get_default_session (),
        SOUP_TYPE_COOKIE_JAR);
}
Пример #29
0
MidoriBrowser*
midori_private_app_new (const gchar* config,
                        const gchar* webapp,
                        gchar**      open_uris,
                        gchar**      execute_commands,
                        gint         inactivity_reset,
                        const gchar* block_uris)
{
    guint i;

    midori_paths_init (MIDORI_RUNTIME_MODE_PRIVATE, config);
#ifndef HAVE_WEBKIT2
    g_object_set_data (G_OBJECT (webkit_get_default_session ()), "pass-through-console", (void*)1);
#endif

    /* Mask the timezone, which can be read by Javascript */
    g_setenv ("TZ", "UTC", TRUE);

    MidoriBrowser* browser = midori_browser_new ();
    g_signal_connect (browser, "new-window",
        G_CALLBACK (midori_frontend_browser_new_window_cb), NULL);

    MidoriWebSettings* settings = midori_settings_new_full (NULL);
    g_object_set (settings,
                  "preferred-languages", "en",
                  "enable-private-browsing", TRUE,
    #ifdef HAVE_LIBSOUP_2_29_91
                  "first-party-cookies-only", TRUE,
    #endif
                  "enable-html5-database", FALSE,
                  "enable-html5-local-storage", FALSE,
                  "enable-offline-web-application-cache", FALSE,
    /* Arguably DNS prefetching is or isn't a privacy concern. For the
     * lack of more fine-grained control we'll go the safe route. */
                  "enable-dns-prefetching", FALSE,
                  "strip-referer", TRUE,
                  "show-panel", FALSE,
                  "last-window-state", MIDORI_WINDOW_NORMAL,
                  "inactivity-reset", inactivity_reset,
                  "block-uris", block_uris,
                  NULL);
    midori_load_soup_session (settings);

    /* In-memory trash for re-opening closed tabs */
    KatzeArray* trash = katze_array_new (KATZE_TYPE_ITEM);
    g_signal_connect_after (trash, "add-item",
      G_CALLBACK (midori_trash_add_item_no_save_cb), NULL);

    KatzeArray* search_engines = midori_search_engines_new_from_folder (NULL);
    g_object_set (browser,
                  "settings", settings,
                  "trash", trash,
                  "search-engines", search_engines,
                  NULL);
    g_object_unref (settings);
    g_object_unref (trash);
    g_object_unref (search_engines);

    midori_browser_set_action_visible (browser, "Tools", FALSE);
    midori_browser_set_action_visible (browser, "ClearPrivateData", FALSE);
#if ENABLE_ADDSPEEDDIAL
    midori_browser_set_action_visible (browser, "AddSpeedDial", FALSE);
#endif
    #if GTK_CHECK_VERSION (3, 0, 0)
    g_object_set (gtk_widget_get_settings (GTK_WIDGET (browser)),
                  "gtk-application-prefer-dark-theme", TRUE,
                  NULL);
    #endif

    if (webapp != NULL)
    {
        gchar* tmp_uri = sokoke_magic_uri (webapp, FALSE, TRUE);
        g_object_set (settings, "homepage", tmp_uri, NULL);
        midori_browser_add_uri (browser, tmp_uri);
        g_free (tmp_uri);
    }

    for (i = 0; open_uris && open_uris[i]; i++)
    {
        gchar* new_uri = sokoke_magic_uri (open_uris[i], FALSE, TRUE);
        midori_browser_add_uri (browser, new_uri);
        g_free (new_uri);
    }
    if (midori_browser_get_n_pages (browser) == 0)
        midori_browser_add_uri (browser, "about:private");
    gtk_widget_show (GTK_WIDGET (browser));

    for (i = 0; execute_commands && execute_commands[i]; i++)
    {
        midori_browser_assert_action (browser, execute_commands[i]);
        midori_browser_activate_action (browser, execute_commands[i]);
    }

    /* FIXME need proper stock extension mechanism */
//由于整合了若干预置扩展,此处相应修改
#if 0
    midori_browser_activate_action (browser, "libtransfers." G_MODULE_SUFFIX "=true");
    midori_browser_activate_action (browser, "libabout." G_MODULE_SUFFIX "=true");
    midori_browser_activate_action (browser, "libopen-with." G_MODULE_SUFFIX "=true");
#else
    midori_browser_activate_action (browser, "libtransfers." G_MODULE_SUFFIX "=true");
    midori_browser_activate_action (browser, "libbuiltinextension." G_MODULE_SUFFIX "=true");
#endif
    
    g_assert (g_module_error () == NULL);

    return browser;
}
Пример #30
0
Файл: uzbl.c Проект: dusanx/uzbl
int
main (int argc, char* argv[]) {
    gtk_init (&argc, &argv);
    if (!g_thread_supported ())
        g_thread_init (NULL);

    printf("Uzbl start location: %s\n", argv[0]);
    strcpy(executable_path,argv[0]);

    strcat ((char *) XDG_CONFIG_HOME_default, getenv ("HOME"));
    strcat ((char *) XDG_CONFIG_HOME_default, "/.config");

    GError *error = NULL;
    GOptionContext* context = g_option_context_new ("- some stuff here maybe someday");
    g_option_context_add_main_entries (context, entries, NULL);
    g_option_context_add_group (context, gtk_get_option_group (TRUE));
    g_option_context_parse (context, &argc, &argv, &error);
    /* initialize hash table */
    bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, free_action);
	
	soup_session = webkit_get_default_session();
    keycmd = g_string_new("");

    settings_init ();
    commands_hash ();

    if (always_insert_mode)
        insert_mode = TRUE;

    GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
    if (status_top)
        gtk_box_pack_start (GTK_BOX (vbox), create_mainbar (), FALSE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0);
    if (!status_top)
        gtk_box_pack_start (GTK_BOX (vbox), create_mainbar (), FALSE, TRUE, 0);

    main_window = create_window ();
    gtk_container_add (GTK_CONTAINER (main_window), vbox);

    load_uri (web_view, uri);

    gtk_widget_grab_focus (GTK_WIDGET (web_view));
    gtk_widget_show_all (main_window);
    xwin = GDK_WINDOW_XID (GTK_WIDGET (main_window)->window);
    printf("window_id %i\n",(int) xwin);
    printf("pid %i\n", getpid ());
    printf("name: %s\n", instance_name);

    scbar_v = (GtkScrollbar*) gtk_vscrollbar_new (NULL);
    bar_v = gtk_range_get_adjustment((GtkRange*) scbar_v);
    scbar_h = (GtkScrollbar*) gtk_hscrollbar_new (NULL);
    bar_h = gtk_range_get_adjustment((GtkRange*) scbar_h);
    gtk_widget_set_scroll_adjustments ((GtkWidget*) web_view, bar_h, bar_v);

    if (!show_status)
        gtk_widget_hide(mainbar);

    if (fifo_dir)
        create_fifo ();
    if (socket_dir)
        create_socket();

    gtk_main ();

    g_string_free(keycmd, TRUE);

    if (fifo_dir)
        unlink (fifo_path);
    if (socket_dir)
        unlink (socket_path);

    g_hash_table_destroy(bindings);
    g_hash_table_destroy(commands);
    return 0;
}