[geary/wip/728002-webkit2: 15/96] Properly build and load the web extension for ClientWebView.



commit 714350ef3abe6b039f6883bd8b900aca29a2bd6d
Author: Michael James Gratton <mike vee net>
Date:   Mon Oct 10 17:54:35 2016 +1100

    Properly build and load the web extension for ClientWebView.
    
    * src/CMakeLists.txt: Pass the build dir through to the application so it
      can work out where to find the extension when running from the source
      tree. Build geary-static as reloacatable so we can link it with the
      extension. Actually link geary-static into the extension and install it.
    
    * src/client/application/geary-application.vala
      (GearyApplication::get_web_extensions_dir): New method that determines
      where the web extension lib is to be found.
    
    * src/client/application/geary-controller.vala
      (GearyController::open_async): Set the extension dir on the WebContext,
      and pass through logging config to the extension.
    
    * src/client/web-process/web-process-extension.vala: Add a
      GearyWebExtension extension object, create it on init and init logging.

 src/CMakeLists.txt                                |   26 +++++++++--------
 src/client/application/geary-application.vala     |   27 ++++++++++++++---
 src/client/application/geary-controller.vala      |    8 +++++
 src/client/web-process/web-process-extension.vala |   32 +++++++++++++++++++-
 test/CMakeLists.txt                               |    4 +-
 5 files changed, 76 insertions(+), 21 deletions(-)
---
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2e5a017..fce9262 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -543,7 +543,10 @@ set(CLIENT_PACKAGES
 )
 
 set(WEB_PROCESS_PACKAGES
-    gtk+-3.0 gee-0.8 webkit2gtk-web-extension-4.0
+  geary-engine
+  gee-0.8
+  gtk+-3.0
+  webkit2gtk-web-extension-4.0
 )
 
 set(CONSOLE_PACKAGES
@@ -557,6 +560,7 @@ set(CFLAGS
     ${DEPS_CFLAGS}
     ${DEPS_CFLAGS_OTHER}
     -D_INSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\"
+    -D_BUILD_ROOT_DIR=\"${CMAKE_BINARY_DIR}\"
     -D_SOURCE_ROOT_DIR=\"${CMAKE_SOURCE_DIR}\"
     -D_GSETTINGS_DIR=\"${CMAKE_BINARY_DIR}/gsettings\"
     -DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\"
@@ -624,6 +628,12 @@ OPTIONS
 
 add_library(geary-engine STATIC ${ENGINE_VALA_C})
 add_dependencies(geary-engine git-version)
+# Build the library statically so we can it statically, but make it
+# relocatable so we can link it to the web extension dynamic lib.
+set_property(
+  TARGET geary-engine
+  PROPERTY POSITION_INDEPENDENT_CODE TRUE
+)
 target_link_libraries(geary-engine m ${DEPS_LIBRARIES} sqlite3-unicodesn)
 
 # Client library (static lib used for building client and unit tests)
@@ -683,21 +693,13 @@ vala_precompile(WEB_PROCESS_VALA_C geary-web-process
 PACKAGES
     ${WEB_PROCESS_PACKAGES}
     ${ENGINE_PACKAGES} ## XXX REMOVE ME
-CUSTOM_VAPIS
-    "${CMAKE_BINARY_DIR}/src/geary-static.vapi"
 OPTIONS
     ${VALAC_OPTIONS}
 )
 
-add_library(geary-web-process ${WEB_PROCESS_VALA_C})
-target_link_libraries(geary-web-process ${DEPS_LIBRARIES} gthread-2.0)
-add_custom_command(
-    TARGET
-        geary-web-process
-    POST_BUILD
-    COMMAND
-        ${CMAKE_COMMAND} -E copy geary-console ${CMAKE_BINARY_DIR}/
-)
+add_library(geary-web-process MODULE ${WEB_PROCESS_VALA_C})
+target_link_libraries(geary-web-process PRIVATE ${DEPS_LIBRARIES} geary-engine)
+install(TARGETS geary-web-process LIBRARY DESTINATION lib/geary/web-extensions)
 
 # Console app
 #################################################
diff --git a/src/client/application/geary-application.vala b/src/client/application/geary-application.vala
index c29e025..ff92f3d 100644
--- a/src/client/application/geary-application.vala
+++ b/src/client/application/geary-application.vala
@@ -8,6 +8,7 @@
 extern const string _INSTALL_PREFIX;
 extern const string _GSETTINGS_DIR;
 extern const string _SOURCE_ROOT_DIR;
+extern const string _BUILD_ROOT_DIR;
 extern const string GETTEXT_PACKAGE;
 
 /**
@@ -27,7 +28,8 @@ public class GearyApplication : Gtk.Application {
     public const string INSTALL_PREFIX = _INSTALL_PREFIX;
     public const string GSETTINGS_DIR = _GSETTINGS_DIR;
     public const string SOURCE_ROOT_DIR = _SOURCE_ROOT_DIR;
-    
+    public const string BUILD_ROOT_DIR = _BUILD_ROOT_DIR;
+
     public const string[] AUTHORS = {
         "Jim Nelson <jim yorba org>",
         "Eric Gregory <eric yorba org>",
@@ -288,12 +290,27 @@ public class GearyApplication : Gtk.Application {
         else
             return File.new_for_path(SOURCE_ROOT_DIR);
     }
-    
-    // Returns the directory the application is currently executing from.
+
+    /** Returns the directory the application is currently executing from. */
     public File get_exec_dir() {
-        return exec_dir;
+        return this.exec_dir;
     }
-    
+
+    /**
+     * Returns the directory containing the application's WebExtension libs.
+     *
+     * If the application is installed, this will be
+     * `$INSTALL_PREFIX/lib/geary/web-extension`, else it will be
+     */
+    public File get_web_extensions_dir() {
+        File? dir = get_install_dir();
+        if (dir != null)
+            dir = dir.get_child("lib").get_child("geary").get_child("web-extensions");
+        else
+            dir = File.new_for_path(BUILD_ROOT_DIR).get_child("src");
+        return dir;
+    }
+
     public File? get_desktop_file() {
         File? install_dir = get_install_dir();
         File desktop_file = (install_dir != null)
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 200b6d5..110a979 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -192,6 +192,14 @@ public class GearyController : Geary.BaseObject {
         WebKit.WebContext context = WebKit.WebContext.get_default();
         context.set_process_model(WebKit.ProcessModel.SHARED_SECONDARY_PROCESS);
         context.set_cache_model(WebKit.CacheModel.DOCUMENT_BROWSER);
+        context.initialize_web_extensions.connect((context) => {
+                context.set_web_extensions_directory(
+                    this.application.get_web_extensions_dir().get_path()
+                );
+                context.set_web_extensions_initialization_user_data(
+                    new Variant.boolean(Args.log_debug)
+                );
+            });
 
         // Use a global avatar session because a cache must be used
         // per-session, and we don't want to have to load the cache
diff --git a/src/client/web-process/web-process-extension.vala 
b/src/client/web-process/web-process-extension.vala
index b063878..948735e 100644
--- a/src/client/web-process/web-process-extension.vala
+++ b/src/client/web-process/web-process-extension.vala
@@ -5,7 +5,35 @@
  * (version 2.1 or later). See the COPYING file in this distribution.
  */
 
+/**
+ * Initialises GearyWebExtension for WebKit web processes.
+ */
+public void webkit_web_extension_initialize_with_user_data(WebKit.WebExtension extension,
+                                                           Variant data) {
+    bool logging_enabled = data.get_boolean();
+
+    Geary.Logging.init();
+    if (logging_enabled)
+        Geary.Logging.log_to(stdout);
+
+    debug("Initialising...");
+
+    // Ref it so it doesn't get free'ed right away
+    GearyWebExtension instance = new GearyWebExtension(extension);
+    instance.ref();
+}
+
+/**
+ * A WebExtension that manages Geary-specific behaviours in web processes.
+ */
+public class GearyWebExtension : Object {
+
+
+    private WebKit.WebExtension extension;
+
+
+    public GearyWebExtension(WebKit.WebExtension extension) {
+        this.extension = extension;
+    }
 
-public static void webkit_web_extension_initialize (WebKit.WebExtension extension) {
-    // noop for now
 }
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index d1d96e4..ba04bf9 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -28,7 +28,7 @@ pkg_check_modules(DEPS REQUIRED
   gthread-2.0
   gtk+-3.0
   libsoup-2.4
-  webkitgtk-3.0
+  webkit2gtk-4.0
 )
 
 set(TEST_PACKAGES
@@ -40,7 +40,7 @@ set(TEST_PACKAGES
   gmime-2.6
   gtk+-3.0
   libsoup-2.4
-  webkitgtk-3.0
+  webkit2gtk-4.0
 )
 
 set(CFLAGS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]