[evolution/wip/mcrha/webkit-jsc-api] Shuffle files a bit
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/mcrha/webkit-jsc-api] Shuffle files a bit
- Date: Wed, 9 Oct 2019 09:05:31 +0000 (UTC)
commit 44d9f1739a3dbd864cfe7979a933384daf0d4aff
Author: Milan Crha <mcrha redhat com>
Date: Wed Oct 9 11:05:38 2019 +0200
Shuffle files a bit
CMakeLists.txt | 1 +
data/CMakeLists.txt | 7 +-
data/webkit/CMakeLists.txt | 10 +++
data/webkit/e-convert.js | 12 ++++
.../webkit/e-web-view.js | 10 +--
data/{ => webkit}/webview-print.css | 0
data/{ => webkit}/webview.css | 0
.../gui/widgets/eab-contact-formatter.c | 2 +-
src/calendar/gui/CMakeLists.txt | 1 -
src/calendar/gui/e-cal-component-preview.c | 2 +-
src/e-util/CMakeLists.txt | 1 +
src/e-util/e-file-request.c | 12 +++-
src/e-util/e-util-private.h | 4 ++
src/e-util/e-win32-reloc.c | 7 ++
src/em-format/CMakeLists.txt | 1 -
src/em-format/e-mail-formatter-print.c | 3 +-
src/em-format/e-mail-formatter.c | 3 +-
src/web-extensions/CMakeLists.txt | 14 ++--
src/web-extensions/e-web-extension.c | 78 ++++++++++++++--------
19 files changed, 108 insertions(+), 60 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b4c1f3757e..b6b6145ae2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -178,6 +178,7 @@ set(plugindir "${privlibdir}/plugins")
set(soundsdir "${privdatadir}/sounds")
set(uidir "${privdatadir}/ui")
set(viewsdir "${privdatadir}/views")
+set(webkitdatadir "${privdatadir}/webkit")
set(webextensionsdir "${privlibdir}/web-extensions")
set(webextensionswebkiteditordir "${webextensionsdir}/webkit-editor")
diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt
index 5f5608a5d2..06e1e17006 100644
--- a/data/CMakeLists.txt
+++ b/data/CMakeLists.txt
@@ -1,6 +1,5 @@
set(filedeps)
set(desktopdir ${SHARE_INSTALL_PREFIX}/applications)
-set(themedir ${privdatadir}/theme)
configure_file(org.gnome.Evolution.desktop.in.in
org.gnome.Evolution.desktop.in
@@ -30,11 +29,6 @@ configure_file(org.gnome.Evolution.appdata.xml.in.in
add_appdata_file(${CMAKE_CURRENT_BINARY_DIR}/org.gnome.Evolution.appdata.xml.in
org.gnome.Evolution.appdata.xml)
-install(FILES webview.css
- webview-print.css
- DESTINATION ${themedir}
-)
-
set(SCHEMAS
org.gnome.evolution.gschema.xml
org.gnome.evolution.addressbook.gschema.xml
@@ -83,3 +77,4 @@ add_subdirectory(images)
add_subdirectory(sounds)
add_subdirectory(ui)
add_subdirectory(views)
+add_subdirectory(webkit)
diff --git a/data/webkit/CMakeLists.txt b/data/webkit/CMakeLists.txt
new file mode 100644
index 0000000000..37832ac9df
--- /dev/null
+++ b/data/webkit/CMakeLists.txt
@@ -0,0 +1,10 @@
+set(DATA_FILES
+ e-convert.js
+ e-web-view.js
+ webview.css
+ webview-print.css
+)
+
+install(FILES ${DATA_FILES}
+ DESTINATION ${webkitdatadir}
+)
diff --git a/data/webkit/e-convert.js b/data/webkit/e-convert.js
new file mode 100644
index 0000000000..4e67b92dc2
--- /dev/null
+++ b/data/webkit/e-convert.js
@@ -0,0 +1,12 @@
+'use strict';
+
+/* semi-convention: private functions start with lower-case letter,
+ public functions start with upper-case letter. */
+
+function EvoConvertToPlainText(element)
+{
+ if (!element)
+ return null;
+
+ return element.innerText;
+}
diff --git a/src/web-extensions/evolution-utils.js b/data/webkit/e-web-view.js
similarity index 99%
rename from src/web-extensions/evolution-utils.js
rename to data/webkit/e-web-view.js
index 963b24bb9d..cd01ed870d 100644
--- a/src/web-extensions/evolution-utils.js
+++ b/data/webkit/e-web-view.js
@@ -396,12 +396,6 @@ Evo.checkAnyParentIsPre = function(node)
return false;
}
-Evo.convertHTMLToPlain = function(node)
-{
- /* TODO */
- return node.innerText;
-}
-
Evo.getElementContent = function(node, format, useOuterHTML)
{
if (!node)
@@ -410,12 +404,12 @@ Evo.getElementContent = function(node, format, useOuterHTML)
var data;
if (format == 1) {
- data = Evo.convertHTMLToPlain(node);
+ data = EvoConvertToPlainText(node);
} else if (format == 2) {
data = useOuterHTML ? node.outerHTML : node.innerHTML;
} else if (format == 3) {
data = {};
- data["plain"] = Evo.convertHTMLToPlain(node);
+ data["plain"] = EvoConvertToPlainText(node);
data["html"] = useOuterHTML ? node.outerHTML : node.innerHTML;
}
diff --git a/data/webview-print.css b/data/webkit/webview-print.css
similarity index 100%
rename from data/webview-print.css
rename to data/webkit/webview-print.css
diff --git a/data/webview.css b/data/webkit/webview.css
similarity index 100%
rename from data/webview.css
rename to data/webkit/webview.css
diff --git a/src/addressbook/gui/widgets/eab-contact-formatter.c
b/src/addressbook/gui/widgets/eab-contact-formatter.c
index 84e62a6b0d..197068a306 100644
--- a/src/addressbook/gui/widgets/eab-contact-formatter.c
+++ b/src/addressbook/gui/widgets/eab-contact-formatter.c
@@ -51,7 +51,7 @@
#define HTML_HEADER "<!doctype html public \"-//W3C//DTD HTML 4.0 TRANSITIONAL//EN\">\n<html>\n" \
"<head>\n<meta name=\"generator\" content=\"Evolution Addressbook Component\">\n" \
-"<link type=\"text/css\" rel=\"stylesheet\" href=\"evo-file://" EVOLUTION_PRIVDATADIR
"/theme/webview.css\">" \
+"<link type=\"text/css\" rel=\"stylesheet\" href=\"evo-file://$EVOLUTION_WEBKITDATADIR/webview.css\">" \
"<style type=\"text/css\">\n" \
" div#header { width:100%; clear: both; }\n" \
" div#columns { width: 100%; clear: both; }\n" \
diff --git a/src/calendar/gui/CMakeLists.txt b/src/calendar/gui/CMakeLists.txt
index dcf5fe171d..405773499f 100644
--- a/src/calendar/gui/CMakeLists.txt
+++ b/src/calendar/gui/CMakeLists.txt
@@ -185,7 +185,6 @@ add_dependencies(evolution-calendar
target_compile_definitions(evolution-calendar PRIVATE
-DG_LOG_DOMAIN=\"evolution-calendar\"
-DEVOLUTION_ETSPECDIR=\"${etspecdir}\"
- -DEVOLUTION_PRIVDATADIR=\"${privdatadir}\"
)
target_compile_options(evolution-calendar PUBLIC
diff --git a/src/calendar/gui/e-cal-component-preview.c b/src/calendar/gui/e-cal-component-preview.c
index e667131732..3f8a1a6aec 100644
--- a/src/calendar/gui/e-cal-component-preview.c
+++ b/src/calendar/gui/e-cal-component-preview.c
@@ -61,7 +61,7 @@ struct _ECalComponentPreviewPrivate {
#define HTML_HEADER "<!doctype html public \"-//W3C//DTD HTML 4.0 TRANSITIONAL//EN\">\n<html>\n" \
"<head>\n<meta name=\"generator\" content=\"Evolution Calendar Component\">\n" \
- "<link type=\"text/css\" rel=\"stylesheet\" href=\"evo-file://" EVOLUTION_PRIVDATADIR
"/theme/webview.css\">\n" \
+ "<link type=\"text/css\" rel=\"stylesheet\"
href=\"evo-file://$EVOLUTION_WEBKITDATADIR/webview.css\">\n" \
"<style>\n" \
".description { font-family: monospace; font-size: 1em; }\n" \
"</style>\n" \
diff --git a/src/e-util/CMakeLists.txt b/src/e-util/CMakeLists.txt
index 5023e8bf03..eb9523d37a 100644
--- a/src/e-util/CMakeLists.txt
+++ b/src/e-util/CMakeLists.txt
@@ -615,6 +615,7 @@ target_compile_definitions(evolution-util PRIVATE
-DEVOLUTION_UIDIR=\"${uidir}\"
-DEVOLUTION_RULEDIR=\"${privdatadir}\"
-DEVOLUTION_WEB_EXTENSIONS_DIR=\"${webextensionsdir}\"
+ -DEVOLUTION_WEBKITDATADIR=\"${webkitdatadir}\"
-DEVOLUTION_TESTGIOMODULESDIR=\"${CMAKE_CURRENT_BINARY_DIR}\"
-DEVOLUTION_TESTTOPSRCDIR=\"${CMAKE_SOURCE_DIR}\"
-DLIBEUTIL_COMPILATION
diff --git a/src/e-util/e-file-request.c b/src/e-util/e-file-request.c
index f58c8093be..090f8cf100 100644
--- a/src/e-util/e-file-request.c
+++ b/src/e-util/e-file-request.c
@@ -59,6 +59,7 @@ e_file_request_process_sync (EContentRequest *request,
GFileInputStream *file_input_stream;
GFileInfo *info;
goffset total_size;
+ gchar *filename = NULL;
SoupURI *suri;
g_return_val_if_fail (E_IS_FILE_REQUEST (request), FALSE);
@@ -70,7 +71,13 @@ e_file_request_process_sync (EContentRequest *request,
suri = soup_uri_new (uri);
g_return_val_if_fail (suri != NULL, FALSE);
- file = g_file_new_for_path (suri->path);
+ if (g_strcmp0 (suri->host, "$EVOLUTION_WEBKITDATADIR") == 0) {
+ filename = g_build_filename (EVOLUTION_WEBKITDATADIR, suri->path, NULL);
+ } else if (g_strcmp0 (suri->host, "$EVOLUTION_IMAGESDIR") == 0) {
+ filename = g_build_filename (EVOLUTION_IMAGESDIR, suri->path, NULL);
+ }
+
+ file = g_file_new_for_path (filename ? filename : suri->path);
file_input_stream = g_file_read (file, cancellable, error);
if (file_input_stream) {
@@ -97,7 +104,7 @@ e_file_request_process_sync (EContentRequest *request,
if (file_input_stream) {
*out_stream = G_INPUT_STREAM (file_input_stream);
*out_stream_length = (gint64) total_size;
- *out_mime_type = g_content_type_guess (suri->path, NULL, 0, NULL);
+ *out_mime_type = g_content_type_guess (filename ? filename : suri->path, NULL, 0, NULL);
} else {
*out_stream = NULL;
*out_stream_length = (gint64) total_size;
@@ -106,6 +113,7 @@ e_file_request_process_sync (EContentRequest *request,
g_object_unref (file);
soup_uri_free (suri);
+ g_free (filename);
return file_input_stream != NULL;
}
diff --git a/src/e-util/e-util-private.h b/src/e-util/e-util-private.h
index 030f2b6cbf..f3ce879f86 100644
--- a/src/e-util/e-util-private.h
+++ b/src/e-util/e-util-private.h
@@ -56,6 +56,7 @@ const gchar *_e_get_sounddir (void) G_GNUC_CONST;
const gchar *_e_get_sysconfdir (void) G_GNUC_CONST;
const gchar *_e_get_toolsdir (void) G_GNUC_CONST;
const gchar *_e_get_uidir (void) G_GNUC_CONST;
+const gchar *_e_get_webkitdatadir (void) G_GNUC_CONST;
#undef DATADIR
#define DATADIR _e_get_datadir ()
@@ -123,6 +124,9 @@ const gchar *_e_get_uidir (void) G_GNUC_CONST;
#undef EVOLUTION_RULEDIR
#define EVOLUTION_RULEDIR _e_get_ruledir ()
+#undef EVOLUTION_WEBKITDATADIR
+#define EVOLUTION_WEBKITDATADIR _e_get_webkitdatadir ()
+
#endif /* G_OS_WIN32 */
#endif /* _E_UTIL_PRIVATE_H_ */
diff --git a/src/e-util/e-win32-reloc.c b/src/e-util/e-win32-reloc.c
index 9a729058b8..dbc7434b06 100644
--- a/src/e-util/e-win32-reloc.c
+++ b/src/e-util/e-win32-reloc.c
@@ -52,6 +52,7 @@ static const gchar *sounddir;
static const gchar *sysconfdir;
static const gchar *toolsdir;
static const gchar *uidir;
+static const gchar *webkitdatadir;
static HMODULE hmodule;
G_LOCK_DEFINE_STATIC (mutex);
@@ -130,6 +131,11 @@ setup (void)
imagesdir = g_getenv ("EVOLUTION_IMAGESDIR");
else
imagesdir = replace_prefix (full_prefix, EVOLUTION_IMAGESDIR);
+ if (g_getenv ("EVOLUTION_WEBKITDATADIR") &&
+ g_file_test (g_getenv ("EVOLUTION_WEBKITDATADIR"), G_FILE_TEST_IS_DIR))
+ webkitdatadir = g_getenv ("EVOLUTION_WEBKITDATADIR");
+ else
+ webkitdatadir = replace_prefix (full_prefix, EVOLUTION_WEBKITDATADIR);
libdir = replace_prefix (full_prefix, EVOLUTION_LIBDIR);
libexecdir = replace_prefix (full_prefix, EVOLUTION_LIBEXECDIR);
moduledir = replace_prefix (full_prefix, EVOLUTION_MODULEDIR);
@@ -176,6 +182,7 @@ GETTER(sounddir)
GETTER(sysconfdir)
GETTER(toolsdir)
GETTER(uidir)
+GETTER(webkitdatadir)
gpointer _e_get_dll_hmodule (void)
{
diff --git a/src/em-format/CMakeLists.txt b/src/em-format/CMakeLists.txt
index 7b6a3d9b21..4a88b8cf95 100644
--- a/src/em-format/CMakeLists.txt
+++ b/src/em-format/CMakeLists.txt
@@ -113,7 +113,6 @@ add_dependencies(evolution-mail-formatter
target_compile_definitions(evolution-mail-formatter PRIVATE
-DG_LOG_DOMAIN=\"evolution-mail-formatter\"
-DEVOLUTION_IMAGESDIR=\"${imagesdir}\"
- -DEVOLUTION_PRIVDATADIR=\"${privdatadir}\"
)
target_compile_options(evolution-mail-formatter PUBLIC
diff --git a/src/em-format/e-mail-formatter-print.c b/src/em-format/e-mail-formatter-print.c
index 1f6cff2721..d302b17a5e 100644
--- a/src/em-format/e-mail-formatter-print.c
+++ b/src/em-format/e-mail-formatter-print.c
@@ -25,8 +25,7 @@
#include <gdk/gdk.h>
#include <glib/gi18n.h>
-#define STYLESHEET_URI \
- "evo-file://" EVOLUTION_PRIVDATADIR "/theme/webview-print.css"
+#define STYLESHEET_URI "evo-file://$EVOLUTION_WEBKITDATADIR/webview-print.css"
/* internal formatter extensions */
GType e_mail_formatter_print_headers_get_type (void);
diff --git a/src/em-format/e-mail-formatter.c b/src/em-format/e-mail-formatter.c
index ce738a85e2..fb88f875ff 100644
--- a/src/em-format/e-mail-formatter.c
+++ b/src/em-format/e-mail-formatter.c
@@ -36,8 +36,7 @@
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_MAIL_FORMATTER, EMailFormatterPrivate))
-#define STYLESHEET_URI \
- "evo-file://" EVOLUTION_PRIVDATADIR "/theme/webview.css"
+#define STYLESHEET_URI "evo-file://$EVOLUTION_WEBKITDATADIR/webview.css"
typedef struct _AsyncContext AsyncContext;
diff --git a/src/web-extensions/CMakeLists.txt b/src/web-extensions/CMakeLists.txt
index 2e2c817f35..aa319bd68c 100644
--- a/src/web-extensions/CMakeLists.txt
+++ b/src/web-extensions/CMakeLists.txt
@@ -1,24 +1,24 @@
-set(GRESOURCE_FILES
- evolution-utils.js
+set(DEPENDENCIES
+ evolution-util
)
-glib_compile_resources(${CMAKE_CURRENT_SOURCE_DIR} evolution-web-extension-resource
evolution_web_extension_resource evolution-web-process-extension.gresource.xml ${GRESOURCE_FILES})
-
set(SOURCES
e-web-extension.h
e-web-extension.c
e-web-extension-main.c
- ${CMAKE_CURRENT_BINARY_DIR}/evolution-web-extension-resource.c
- ${CMAKE_CURRENT_BINARY_DIR}/evolution-web-extension-resource.h
)
add_library(ewebextension MODULE
${SOURCES}
)
+add_dependencies(ewebextension
+ ${DEPENDENCIES}
+)
+
target_compile_definitions(ewebextension PRIVATE
-DG_LOG_DOMAIN=\"ewebextension\"
- -DEVOLUTION_IMAGESDIR=\"${imagesdir}\"
+ -DEVOLUTION_WEBKITDATADIR=\"${webkitdatadir}\"
)
target_compile_options(ewebextension PUBLIC
diff --git a/src/web-extensions/e-web-extension.c b/src/web-extensions/e-web-extension.c
index 78f4af890e..90e7970681 100644
--- a/src/web-extensions/e-web-extension.c
+++ b/src/web-extensions/e-web-extension.c
@@ -29,6 +29,10 @@
#include <webkitdom/webkitdom.h>
+#define E_UTIL_INCLUDE_WITHOUT_WEBKIT
+#include <e-util/e-util.h>
+#undef E_UTIL_INCLUDE_WITHOUT_WEBKIT
+
#include "e-web-extension.h"
struct _EWebExtensionPrivate {
@@ -136,51 +140,67 @@ web_page_created_cb (WebKitWebExtension *wk_extension,
}
static void
-window_object_cleared_cb (WebKitScriptWorld *world,
- WebKitWebPage *page,
- WebKitFrame *frame,
- gpointer user_data)
+load_javascript_file (JSCContext *jsc_context,
+ const gchar *js_filename)
{
- JSCContext *jsc_context;
JSCValue *result;
- GBytes *bytes;
- gconstpointer data;
- gsize data_size = 0;
+ JSCException *exception;
+ gchar *content, *filename, *resource_uri;
+ gsize length = 0;
GError *error = NULL;
- /* Load the evolution-utils.js only to the main frame, not to the subframes */
- if (!webkit_frame_is_main_frame (frame))
- return;
+ g_return_if_fail (jsc_context != NULL);
+
+ filename = g_build_filename (EVOLUTION_WEBKITDATADIR, js_filename, NULL);
+
+ if (!g_file_get_contents (filename, &content, &length, &error)) {
+ g_warning ("Failed to load '%s': %s", filename, error ? error->message : "Unknown error");
- bytes = g_resources_lookup_data ("/org/gnome/evolution-web-process-extension/js/evolution-utils.js",
G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
- if (!bytes) {
- g_warning ("Failed to load evolution-utils.js: %s", error ? error->message : "Unknown error");
g_clear_error (&error);
+ g_free (filename);
+
return;
}
- jsc_context = webkit_frame_get_js_context (frame);
- data = g_bytes_get_data (bytes, &data_size);
+ resource_uri = g_strconcat ("resource:///", js_filename, NULL);
- /* Preload utility functions */
- result = jsc_context_evaluate_with_source_uri (jsc_context, data, data_size,
"resource:///evolution-utils.js", 1);
+ result = jsc_context_evaluate_with_source_uri (jsc_context, content, length, resource_uri, 1);
- if (result) {
- JSCException *exception;
+ g_free (resource_uri);
- exception = jsc_context_get_exception (jsc_context);
+ exception = jsc_context_get_exception (jsc_context);
- if (exception) {
- g_warning ("Failed to call initial script for %s-frame: %d:%d: %s",
- webkit_frame_is_main_frame (frame) ? "main" : "sub",
- jsc_exception_get_line_number (exception),
- jsc_exception_get_column_number (exception),
- jsc_exception_get_message (exception));
- }
+ if (exception) {
+ g_warning ("Failed to call script '%s': %d:%d: %s",
+ filename,
+ jsc_exception_get_line_number (exception),
+ jsc_exception_get_column_number (exception),
+ jsc_exception_get_message (exception));
}
- g_clear_pointer (&bytes, g_bytes_unref);
g_clear_object (&result);
+ g_free (filename);
+ g_free (content);
+}
+
+static void
+window_object_cleared_cb (WebKitScriptWorld *world,
+ WebKitWebPage *page,
+ WebKitFrame *frame,
+ gpointer user_data)
+{
+ JSCContext *jsc_context;
+
+ /* Load the javascript files only to the main frame, not to the subframes */
+ if (!webkit_frame_is_main_frame (frame))
+ return;
+
+ jsc_context = webkit_frame_get_js_context (frame);
+
+ /* Read e-convert.js first, because e-web-view.js uses it */
+ load_javascript_file (jsc_context, "e-convert.js");
+ load_javascript_file (jsc_context, "e-web-view.js");
+
g_clear_object (&jsc_context);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]