aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--embed/ephy-web-app-utils.c178
-rw-r--r--embed/ephy-web-app-utils.h5
-rw-r--r--embed/ephy-web-view.c164
-rw-r--r--src/window-commands.c7
4 files changed, 187 insertions, 167 deletions
diff --git a/embed/ephy-web-app-utils.c b/embed/ephy-web-app-utils.c
index d499552f7..8a427c0ef 100644
--- a/embed/ephy-web-app-utils.c
+++ b/embed/ephy-web-app-utils.c
@@ -23,9 +23,13 @@
#include "ephy-web-app-utils.h"
+#include "ephy-debug.h"
#include "ephy-file-helpers.h"
#include "ephy-web-view.h"
+#include <glib/gstdio.h>
+#include <libsoup/soup-gnome.h>
+
static gboolean
_g_directory_delete_recursively (GFile *directory, GError **error)
{
@@ -152,3 +156,177 @@ out:
return return_value;
}
+
+#define EPHY_WEB_APP_TOOLBAR "<?xml version=\"1.0\"?>" \
+ "<toolbars version=\"1.1\">" \
+ " <toolbar name=\"DefaultToolbar\" hidden=\"true\" editable=\"false\">" \
+ " <toolitem name=\"NavigationBack\"/>" \
+ " <toolitem name=\"NavigationForward\"/>" \
+ " <toolitem name=\"ViewReload\"/>" \
+ " <toolitem name=\"ViewCancel\"/>" \
+ " </toolbar>" \
+ "</toolbars>"
+
+#define EPHY_TOOLBARS_XML_FILE "epiphany-toolbars-3.xml"
+
+static char *
+create_desktop_file (EphyWebView *view,
+ const char *profile_dir,
+ const char *title,
+ GdkPixbuf *icon)
+{
+ GKeyFile *file;
+ char *exec_string;
+ char *data;
+ char *filename, *desktop_file_path;
+ char *link_path;
+ GFile *link;
+
+ g_return_val_if_fail (profile_dir, NULL);
+
+ file = g_key_file_new ();
+ g_key_file_set_value (file, "Desktop Entry", "Name", title);
+ exec_string = g_strdup_printf ("epiphany --application-mode --profile=\"%s\" %s",
+ profile_dir,
+ webkit_web_view_get_uri (WEBKIT_WEB_VIEW (view)));
+ g_key_file_set_value (file, "Desktop Entry", "Exec", exec_string);
+ g_free (exec_string);
+ g_key_file_set_value (file, "Desktop Entry", "StartupNotification", "true");
+ g_key_file_set_value (file, "Desktop Entry", "Terminal", "false");
+ g_key_file_set_value (file, "Desktop Entry", "Type", "Application");
+
+ if (icon) {
+ GOutputStream *stream;
+ char *path;
+ GFile *image;
+
+ path = g_build_filename (profile_dir, "app-icon.png", NULL);
+ image = g_file_new_for_path (path);
+
+ stream = (GOutputStream*)g_file_create (image, 0, NULL, NULL);
+ gdk_pixbuf_save_to_stream (icon, stream, "png", NULL, NULL, NULL);
+ g_key_file_set_value (file, "Desktop Entry", "Icon", path);
+
+ g_object_unref (stream);
+ g_object_unref (image);
+ g_free (path);
+ }
+
+ g_key_file_set_value (file, "Desktop Entry", "StartupWMClass", title);
+
+ data = g_key_file_to_data (file, NULL, NULL);
+ filename = g_strconcat (title, ".desktop", NULL);
+ desktop_file_path = g_build_filename (profile_dir, filename, NULL);
+ g_key_file_free (file);
+
+ if (!g_file_set_contents (desktop_file_path, data, -1, NULL)) {
+ g_free (desktop_file_path);
+ desktop_file_path = NULL;
+ }
+
+ g_free (data);
+
+ /* Create a symlink in XDG_DATA_DIR/applications for the Shell to
+ * pick up this application. */
+ link_path = g_build_filename (g_get_user_data_dir (), "applications", filename, NULL);
+ link = g_file_new_for_path (link_path);
+ g_free (link_path);
+ g_file_make_symbolic_link (link, desktop_file_path, NULL, NULL);
+ g_object_unref (link);
+ g_free (filename);
+
+ return desktop_file_path;
+}
+
+static void
+create_cookie_jar_for_domain (EphyWebView *view, const char *directory)
+{
+ SoupSession *session;
+ GSList *cookies, *p;
+ SoupCookieJar *current_jar, *new_jar;
+ char *domain, *filename;
+ SoupURI *uri;
+
+ /* Create the new cookie jar */
+ filename = g_build_filename (directory, "cookies.sqlite", NULL);
+ new_jar = (SoupCookieJar*)soup_cookie_jar_sqlite_new (filename, FALSE);
+ g_free (filename);
+
+ /* The app domain for the current view */
+ uri = soup_uri_new (webkit_web_view_get_uri (WEBKIT_WEB_VIEW (view)));
+ domain = uri->host;
+
+ /* The current cookies */
+ session = webkit_get_default_session ();
+ current_jar = (SoupCookieJar*)soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR);
+ cookies = soup_cookie_jar_all_cookies (current_jar);
+
+ for (p = cookies; p; p = p->next) {
+ SoupCookie *cookie = (SoupCookie*)p->data;
+
+ if (g_str_has_suffix (cookie->domain, domain))
+ soup_cookie_jar_add_cookie (new_jar, cookie);
+ else
+ soup_cookie_free (cookie);
+ }
+
+ soup_uri_free (uri);
+ g_slist_free (cookies);
+}
+
+/**
+ * ephy_web_application_create:
+ * @view: an #EphyWebView
+ * @title: the title for the new web application
+ * @icon: the icon for the new web application
+ *
+ * Creates a new Web Application from the currently loaded URI in the @view.
+ *
+ * Returns: (transfer-full): the path to the desktop file representing the new application
+ **/
+char *
+ephy_web_application_create (EphyWebView *view, const char *title, GdkPixbuf *icon)
+{
+ char *profile_dir = NULL;
+ char *toolbar_path = NULL;
+ char *desktop_file_path = NULL;
+
+ g_return_val_if_fail (EPHY_IS_WEB_VIEW (view), NULL);
+
+ /* If there's already a WebApp profile for the contents of this
+ * view, do nothing. TODO: create a method to check this and use it
+ * to ask the user if she wants to overwrite the existing WebApp. */
+ profile_dir = ephy_web_application_get_profile_directory (title);
+ if (g_file_test (profile_dir, G_FILE_TEST_IS_DIR))
+ goto out;
+
+ /* Create the profile directory, populate it. */
+ if (g_mkdir (profile_dir, 488) == -1) {
+ LOG ("Failed to create directory %s", profile_dir);
+ goto out;
+ }
+
+ /* Things we need in a WebApp's profile:
+ - Toolbar layout
+ - Our own cookies file, copying the relevant cookies for the
+ app's domain.
+ */
+ toolbar_path = g_build_filename (profile_dir, EPHY_TOOLBARS_XML_FILE, NULL);
+ if (!g_file_set_contents (toolbar_path, EPHY_WEB_APP_TOOLBAR, -1, NULL))
+ goto out;
+
+ create_cookie_jar_for_domain (view, profile_dir);
+
+ /* Create the deskop file. */
+ desktop_file_path = create_desktop_file (view, profile_dir, title, icon);
+
+out:
+ if (toolbar_path)
+ g_free (toolbar_path);
+
+ if (profile_dir)
+ g_free (profile_dir);
+
+ return desktop_file_path;
+}
+
diff --git a/embed/ephy-web-app-utils.h b/embed/ephy-web-app-utils.h
index 560f1de09..d6f7be516 100644
--- a/embed/ephy-web-app-utils.h
+++ b/embed/ephy-web-app-utils.h
@@ -25,11 +25,16 @@
#define EPHY_WEB_APP_UTILS_H
#include <glib.h>
+#include <gtk/gtk.h>
+
+#include "ephy-web-view.h"
G_BEGIN_DECLS
#define EPHY_WEB_APP_PREFIX "app-"
+char *ephy_web_application_create (EphyWebView *view, const char *title, GdkPixbuf *icon);
+
gboolean ephy_web_application_delete (const char *name);
char *ephy_web_application_get_profile_directory (const char *app_name);
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 9aefdeddf..89eb5eb6a 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -48,7 +48,6 @@
#include "ephy-request-about.h"
#include "ephy-settings.h"
#include "ephy-string.h"
-#include "ephy-web-app-utils.h"
#include "ephy-web-view.h"
#include "ephy-zoom.h"
@@ -3687,169 +3686,6 @@ ephy_web_view_load_homepage (EphyWebView *view)
return is_empty;
}
-#define EPHY_WEB_APP_TOOLBAR "<?xml version=\"1.0\"?>" \
- "<toolbars version=\"1.1\">" \
- " <toolbar name=\"DefaultToolbar\" hidden=\"true\" editable=\"false\">" \
- " <toolitem name=\"NavigationBack\"/>" \
- " <toolitem name=\"NavigationForward\"/>" \
- " <toolitem name=\"ViewReload\"/>" \
- " <toolitem name=\"ViewCancel\"/>" \
- " </toolbar>" \
- "</toolbars>"
-
-#define EPHY_TOOLBARS_XML_FILE "epiphany-toolbars-3.xml"
-
-static char *
-create_desktop_file (EphyWebView *view,
- const char *profile_dir,
- const char *title,
- GdkPixbuf *icon)
-{
- GKeyFile *file;
- char *exec_string;
- char *data;
- char *filename, *desktop_file_path;
- char *link_path;
- GFile *link;
-
- g_return_val_if_fail (profile_dir, NULL);
-
- file = g_key_file_new ();
- g_key_file_set_value (file, "Desktop Entry", "Name", title);
- exec_string = g_strdup_printf ("epiphany --application-mode --profile=\"%s\" %s",
- profile_dir,
- webkit_web_view_get_uri (WEBKIT_WEB_VIEW (view)));
- g_key_file_set_value (file, "Desktop Entry", "Exec", exec_string);
- g_free (exec_string);
- g_key_file_set_value (file, "Desktop Entry", "StartupNotification", "true");
- g_key_file_set_value (file, "Desktop Entry", "Terminal", "false");
- g_key_file_set_value (file, "Desktop Entry", "Type", "Application");
-
- if (icon) {
- GOutputStream *stream;
- char *path;
- GFile *image;
-
- path = g_build_filename (profile_dir, "app-icon.png", NULL);
- image = g_file_new_for_path (path);
-
- stream = (GOutputStream*)g_file_create (image, 0, NULL, NULL);
- gdk_pixbuf_save_to_stream (icon, stream, "png", NULL, NULL, NULL);
- g_key_file_set_value (file, "Desktop Entry", "Icon", path);
-
- g_object_unref (stream);
- g_object_unref (image);
- g_free (path);
- }
-
- g_key_file_set_value (file, "Desktop Entry", "StartupWMClass", title);
-
- data = g_key_file_to_data (file, NULL, NULL);
- filename = g_strconcat (title, ".desktop", NULL);
- desktop_file_path = g_build_filename (profile_dir, filename, NULL);
- g_key_file_free (file);
-
- if (!g_file_set_contents (desktop_file_path, data, -1, NULL)) {
- g_free (desktop_file_path);
- desktop_file_path = NULL;
- }
-
- g_free (data);
-
- /* Create a symlink in XDG_DATA_DIR/applications for the Shell to
- * pick up this application. */
- link_path = g_build_filename (g_get_user_data_dir (), "applications", filename, NULL);
- link = g_file_new_for_path (link_path);
- g_free (link_path);
- g_file_make_symbolic_link (link, desktop_file_path, NULL, NULL);
- g_object_unref (link);
- g_free (filename);
-
- return desktop_file_path;
-}
-
-static void
-create_cookie_jar_for_domain (EphyWebView *view, const char *directory)
-{
- SoupSession *session;
- GSList *cookies, *p;
- SoupCookieJar *current_jar, *new_jar;
- char *domain, *filename;
- SoupURI *uri;
-
- /* Create the new cookie jar */
- filename = g_build_filename (directory, "cookies.sqlite", NULL);
- new_jar = (SoupCookieJar*)soup_cookie_jar_sqlite_new (filename, FALSE);
- g_free (filename);
-
- /* The app domain for the current view */
- uri = soup_uri_new (webkit_web_view_get_uri (WEBKIT_WEB_VIEW (view)));
- domain = uri->host;
-
- /* The current cookies */
- session = webkit_get_default_session ();
- current_jar = (SoupCookieJar*)soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR);
- cookies = soup_cookie_jar_all_cookies (current_jar);
-
- for (p = cookies; p; p = p->next) {
- SoupCookie *cookie = (SoupCookie*)p->data;
-
- if (g_str_has_suffix (cookie->domain, domain))
- soup_cookie_jar_add_cookie (new_jar, cookie);
- else
- soup_cookie_free (cookie);
- }
-
- soup_uri_free (uri);
- g_slist_free (cookies);
-}
-
-char *
-ephy_web_view_create_web_application (EphyWebView *view, const char *title, GdkPixbuf *icon)
-{
- char *profile_dir = NULL;
- char *toolbar_path = NULL;
- char *desktop_file_path = NULL;
-
- g_return_val_if_fail (EPHY_IS_WEB_VIEW (view), NULL);
-
- /* If there's already a WebApp profile for the contents of this
- * view, do nothing. TODO: create a method to check this and use it
- * to ask the user if she wants to overwrite the existing WebApp. */
- profile_dir = ephy_web_application_get_profile_directory (title);
- if (g_file_test (profile_dir, G_FILE_TEST_IS_DIR))
- goto out;
-
- /* Create the profile directory, populate it. */
- if (g_mkdir (profile_dir, 488) == -1) {
- LOG ("Failed to create directory %s", profile_dir);
- goto out;
- }
-
- /* Things we need in a WebApp's profile:
- - Toolbar layout
- - Our own cookies file, copying the relevant cookies for the
- app's domain.
- */
- toolbar_path = g_build_filename (profile_dir, EPHY_TOOLBARS_XML_FILE, NULL);
- if (!g_file_set_contents (toolbar_path, EPHY_WEB_APP_TOOLBAR, -1, NULL))
- goto out;
-
- create_cookie_jar_for_domain (view, profile_dir);
-
- /* Create the deskop file. */
- desktop_file_path = create_desktop_file (view, profile_dir, title, icon);
-
-out:
- if (toolbar_path)
- g_free (toolbar_path);
-
- if (profile_dir)
- g_free (profile_dir);
-
- return desktop_file_path;
-}
-
/**
* ephy_web_view_get_snapshot: takes a snapshot of the requested region of a #EphyWebView
* @view: the #EphyWebView
diff --git a/src/window-commands.c b/src/window-commands.c
index 90a7f51aa..bb3fcc0b5 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -51,6 +51,7 @@
#include "ephy-stock-icons.h"
#include "ephy-string.h"
#include "pdm-dialog.h"
+#include "ephy-web-app-utils.h"
#include <string.h>
#include <glib.h>
@@ -578,9 +579,9 @@ window_cmd_file_save_as_application (GtkAction *action,
NotifyNotification *notification;
/* Create Web Application, including a new profile and .desktop file. */
- desktop_file = ephy_web_view_create_web_application (view,
- gtk_entry_get_text (GTK_ENTRY (data->entry)),
- gtk_image_get_pixbuf (GTK_IMAGE (data->image)));
+ desktop_file = ephy_web_application_create (view,
+ gtk_entry_get_text (GTK_ENTRY (data->entry)),
+ gtk_image_get_pixbuf (GTK_IMAGE (data->image)));
message = g_strdup_printf (_("The application '%s' is ready to be used"),
gtk_entry_get_text (GTK_ENTRY (data->entry)));