[geary/bug/728002-webkit2: 8/140] Implement loading cid: scheme resources in ClientWebView.



commit 0dbf925a86661b9190fdd94a63a1f21942c32748
Author: Michael James Gratton <mike vee net>
Date:   Mon Oct 10 18:15:30 2016 +1100

    Implement loading cid: scheme resources in ClientWebView.
    
    * src/client/application/geary-controller.vala
      (GearyController::open_async): Register a handler for the 'cid' scheme.
    
    * src/client/components/client-web-view.vala
      (ClientWebView::handle_cid_request): Hook up requests for cid URIs
      using attachment files.

 src/client/application/geary-controller.vala |    6 ++++++
 src/client/components/client-web-view.vala   |   18 ++++++++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 110a979..199b8d2 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -192,6 +192,12 @@ 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.register_uri_scheme("cid", (req) => {
+                ClientWebView? view = req.get_web_view() as ClientWebView;
+                if (view != null) {
+                    view.handle_cid_request(req);
+                }
+            });
         context.initialize_web_extensions.connect((context) => {
                 context.set_web_extensions_directory(
                     this.application.get_web_extensions_dir().get_path()
diff --git a/src/client/components/client-web-view.vala b/src/client/components/client-web-view.vala
index 547c9bf..e0dfae0 100644
--- a/src/client/components/client-web-view.vala
+++ b/src/client/components/client-web-view.vala
@@ -130,6 +130,24 @@ public class ClientWebView : WebKit.WebView {
         this.zoom_level -= (this.zoom_level * ZOOM_FACTOR);
     }
 
+    internal void handle_cid_request(WebKit.URISchemeRequest request) {
+        const string CID_PREFIX = "cid:";
+
+        string cid = request.get_uri().substring(CID_PREFIX.length);
+        File? file = this.cid_resources[cid];
+        if (file != null) {
+            try {
+                request.finish(file.read(), -1, null);
+            } catch (Error err) {
+                request.finish_error(err);
+            }
+        } else {
+            request.finish_error(
+                new FileError.NOENT("Unknown CID: %s".printf(cid))
+            );
+        }
+    }
+
     // Only allow string-based page loads, and notify but ignore if
     // the user attempts to click on a link. Deny everything else.
     private bool on_decide_policy(WebKit.WebView view,


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