diff options
author | Carlos Garcia Campos <cgarcia@igalia.com> | 2013-03-29 00:06:47 +0800 |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2013-04-05 21:47:37 +0800 |
commit | a2181b928e5a0f6d27487859fe86a276c1eed25c (patch) | |
tree | 9a4915e37cb5f7f75ff686c8936bc34b47ea481c | |
parent | efccc1eac4ac4e15fd4f5695d27a85c7d25c3cc6 (diff) | |
download | gsoc2013-epiphany-a2181b928e5a0f6d27487859fe86a276c1eed25c.tar gsoc2013-epiphany-a2181b928e5a0f6d27487859fe86a276c1eed25c.tar.gz gsoc2013-epiphany-a2181b928e5a0f6d27487859fe86a276c1eed25c.tar.bz2 gsoc2013-epiphany-a2181b928e5a0f6d27487859fe86a276c1eed25c.tar.lz gsoc2013-epiphany-a2181b928e5a0f6d27487859fe86a276c1eed25c.tar.xz gsoc2013-epiphany-a2181b928e5a0f6d27487859fe86a276c1eed25c.tar.zst gsoc2013-epiphany-a2181b928e5a0f6d27487859fe86a276c1eed25c.zip |
Compile template pages as GResources
So that they are loaded from memory instead of disk every time they are
needed.
We also get rid of ephy_file searching for the files in the file system.
https://bugzilla.gnome.org/show_bug.cgi?id=696792
-rw-r--r-- | data/pages/Makefile.am | 8 | ||||
-rw-r--r-- | embed/ephy-web-view.c | 24 | ||||
-rw-r--r-- | src/Makefile.am | 11 | ||||
-rw-r--r-- | src/epiphany.gresource.xml | 3 | ||||
-rw-r--r-- | src/resources/error.html (renamed from data/pages/error.html) | 0 | ||||
-rw-r--r-- | src/resources/process-crash.html (renamed from data/pages/process_crash.html) | 0 | ||||
-rw-r--r-- | src/resources/recovery.html (renamed from data/pages/recovery.html) | 0 | ||||
-rw-r--r-- | tests/Makefile.am | 1 |
8 files changed, 23 insertions, 24 deletions
diff --git a/data/pages/Makefile.am b/data/pages/Makefile.am index 4b00a41b5..0ff154064 100644 --- a/data/pages/Makefile.am +++ b/data/pages/Makefile.am @@ -1,11 +1,5 @@ -errorpagesdir = $(pkgdatadir)/pages -errorpages_DATA = \ - recovery.html \ - process_crash.html \ - error.html - stylepagesdir = $(pkgdatadir)/pages stylepages_DATA = \ about.css -EXTRA_DIST = $(errorpages_DATA) $(stylepages_DATA) +EXTRA_DIST = $(stylepages_DATA) diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c index ce0312ad1..92cdb3896 100644 --- a/embed/ephy-web-view.c +++ b/embed/ephy-web-view.c @@ -63,6 +63,10 @@ #define MAX_TITLE_LENGTH 512 /* characters */ #define EMPTY_PAGE _("Blank page") /* Title for the empty page */ +#define EPHY_PAGE_TEMPLATE_ERROR "/org/gnome/epiphany/page-templates/error.html" +#define EPHY_PAGE_TEMPLATE_RECOVERY "/org/gnome/epiphany/page-templates/recovery.html" +#define EPHY_PAGE_TEMPLATE_PROCESS_CRASH "/org/gnome/epiphany/page-templates/process-crash.html" + struct _EphyWebViewPrivate { EphyWebViewSecurityLevel security_level; EphyWebViewDocumentType document_type; @@ -1699,22 +1703,17 @@ ephy_web_view_load_error_page (EphyWebView *view, { GString *html = g_string_new (""); const char *reason; - char *hostname; char *lang; - char *page_title; char *msg_title; char *msg; char *button_label; - const char *html_file; + GBytes *html_file; const char *stock_icon; - GtkIconInfo *icon_info; char *image_data; - char *template; - if (error) reason = error->message; else @@ -1741,7 +1740,7 @@ ephy_web_view_load_error_page (EphyWebView *view, button_label = g_strdup (_("Try again")); - html_file = ephy_file ("error.html"); + html_file = g_resources_lookup_data (EPHY_PAGE_TEMPLATE_ERROR, 0, NULL); stock_icon = "dialog-error"; break; case EPHY_WEB_VIEW_ERROR_PAGE_CRASH: @@ -1759,7 +1758,7 @@ ephy_web_view_load_error_page (EphyWebView *view, button_label = g_strdup (_("Load again anyway")); - html_file = ephy_file ("recovery.html"); + html_file = g_resources_lookup_data (EPHY_PAGE_TEMPLATE_RECOVERY, 0, NULL); stock_icon = "dialog-information"; break; case EPHY_WEB_VIEW_ERROR_PROCESS_CRASH: @@ -1768,7 +1767,7 @@ ephy_web_view_load_error_page (EphyWebView *view, msg = g_strdup (_("Something went wrong while displaying this page. Please reload or visit a different page to continue.")); button_label = NULL; - html_file = ephy_file ("process_crash.html"); + html_file = g_resources_lookup_data (EPHY_PAGE_TEMPLATE_PROCESS_CRASH, 0, NULL); stock_icon = "computer-fail-symbolic"; break; @@ -1785,13 +1784,12 @@ ephy_web_view_load_error_page (EphyWebView *view, image_data = icon_info ? ephy_file_create_data_uri_for_filename (gtk_icon_info_get_filename (icon_info), NULL) : NULL; - g_file_get_contents (html_file, &template, NULL, NULL); - ephy_web_view_set_title (view, page_title); _ephy_web_view_update_icon (view); - g_string_printf (html, template, + g_string_printf (html, + g_bytes_get_data (html_file, NULL), lang, lang, ((gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) ? "rtl" : "ltr"), page_title, @@ -1799,7 +1797,7 @@ ephy_web_view_load_error_page (EphyWebView *view, image_data ? image_data : "", msg_title, msg, button_label); - g_free (template); + g_bytes_unref (html_file); g_free (lang); g_free (page_title); g_free (msg_title); diff --git a/src/Makefile.am b/src/Makefile.am index 290ca0fb0..b7e6448ad 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,7 +8,7 @@ bin_PROGRAMS = epiphany EXTRA_DIST = \ epiphany.gresource.xml \ - $(UI_FILES) \ + $(RESOURCE_FILES) \ $(NULL) NOINST_H_FILES = \ @@ -98,7 +98,7 @@ libephymain_la_CFLAGS = \ $(CODE_COVERAGE_CFLAGS) \ $(AM_CFLAGS) -UI_FILES = \ +RESOURCE_FILES = \ resources/epiphany-bookmark-editor-ui.xml \ resources/epiphany-history-window-ui.xml \ resources/epiphany-ui.xml \ @@ -106,12 +106,15 @@ UI_FILES = \ resources/epiphany-application-menu.ui \ resources/prefs-dialog.ui \ resources/epiphany.css \ + resources/error.html \ + resources/process-crash.html \ + resources/recovery.html \ $(NULL) -epiphany-resources.c: epiphany.gresource.xml $(UI_FILES) +epiphany-resources.c: epiphany.gresource.xml $(RESOURCE_FILES) $(AM_V_GEN)glib-compile-resources --target=$@ --sourcedir=$(srcdir)/resources --generate-source --c-name epiphany $(srcdir)/epiphany.gresource.xml -epiphany-resources.h: epiphany.gresource.xml $(UI_FILES) +epiphany-resources.h: epiphany.gresource.xml $(RESOURCE_FILES) $(AM_V_GEN)glib-compile-resources --target=$@ --sourcedir=$(srcdir)/resources --generate-header --c-name epiphany $(srcdir)/epiphany.gresource.xml EPIPHANY_RESOURCES = \ diff --git a/src/epiphany.gresource.xml b/src/epiphany.gresource.xml index b75646667..8e4d719a4 100644 --- a/src/epiphany.gresource.xml +++ b/src/epiphany.gresource.xml @@ -8,5 +8,8 @@ <file preprocess="xml-stripblanks">epiphany-bookmark-editor-ui.xml</file> <file preprocess="xml-stripblanks">epiphany-history-window-ui.xml</file> <file>epiphany.css</file> + <file alias="page-templates/error.html" compressed="true">error.html</file> + <file alias="page-templates/process-crash.html" compressed="true">process-crash.html</file> + <file alias="page-templates/recovery.html" compressed="true">recovery.html</file> </gresource> </gresources> diff --git a/data/pages/error.html b/src/resources/error.html index 9aa39f605..9aa39f605 100644 --- a/data/pages/error.html +++ b/src/resources/error.html diff --git a/data/pages/process_crash.html b/src/resources/process-crash.html index 7cf7ab93c..7cf7ab93c 100644 --- a/data/pages/process_crash.html +++ b/src/resources/process-crash.html diff --git a/data/pages/recovery.html b/src/resources/recovery.html index 9aa39f605..9aa39f605 100644 --- a/data/pages/recovery.html +++ b/src/resources/recovery.html diff --git a/tests/Makefile.am b/tests/Makefile.am index b69d60284..1db8a32c7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -177,6 +177,7 @@ test_ephy_web_app_utils_SOURCES = \ ephy-web-app-utils-test.c test_ephy_web_view_SOURCES = \ + $(top_builddir)/src/epiphany-resources.c \ ephy-web-view-test.c EXTRA_DIST = \ |