[libbluray-devel] Fix Xlet-initiated font caching: delegate caching to privileged context

hpi1 git at videolan.org
Fri Oct 2 10:51:02 CEST 2015


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Thu Sep 17 18:35:58 2015 +0300| [0697e4a549399c5a839c961d502245b9391e044e] | committer: hpi1

Fix Xlet-initiated font caching: delegate caching to privileged context

This seems to be used mostly in BD+ error messages

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=0697e4a549399c5a839c961d502245b9391e044e
---

 ChangeLog                                          |    2 +
 src/libbluray/bdj/java/org/videolan/BDJLoader.java |   55 +++++++++++++++++++-
 2 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ffc7788..a20ca9a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+- Fix Xlet-initiated font caching.
+
 2015-05-15: Version 0.8.1
 - Notify application when UO mask changes.
 - Improved error resilience.
diff --git a/src/libbluray/bdj/java/org/videolan/BDJLoader.java b/src/libbluray/bdj/java/org/videolan/BDJLoader.java
index 30fb8c4..59410c5 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJLoader.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJLoader.java
@@ -44,8 +44,60 @@ import org.videolan.media.content.PlayerManager;
 
 public class BDJLoader {
 
+    private static class FontCacheAction extends BDJAction {
+        public FontCacheAction(InputStream is) {
+            this.fontPath = null;
+            this.is = is;
+        }
+        public FontCacheAction(String fontPath) {
+            this.fontPath = fontPath;
+            this.is = null;
+        }
+
+        protected void doAction() {
+            try {
+                if (this.is != null) {
+                    this.cacheFile = addFontImpl(is);
+                } else {
+                    this.cacheFile = addFontImpl(fontPath);
+                }
+            } catch (RuntimeException e) {
+                this.exception = e;
+            }
+        }
+
+        public File execute() {
+            BDJActionManager.getInstance().putCommand(this);
+            waitEnd();
+            if (exception != null) {
+                throw exception;
+            }
+            return cacheFile;
+        }
+
+        private final String fontPath;
+        private final InputStream is;
+        private File cacheFile = null;
+        private RuntimeException exception = null;
+    }
+
     /* called by org.dvb.ui.FontFactory */
     public static File addFont(InputStream is) {
+        if (BDJXletContext.getCurrentContext() == null)
+            return addFontImpl(is);
+        /* dispatch cache request to privileged thread */
+        return new FontCacheAction(is).execute();
+    }
+
+    /* called by org.dvb.ui.FontFactory */
+    public static File addFont(String fontFile) {
+        if (BDJXletContext.getCurrentContext() == null)
+            return addFontImpl(fontFile);
+        /* dispatch cache request to privileged thread */
+        return new FontCacheAction(fontFile).execute();
+    }
+
+    private static File addFontImpl(InputStream is) {
         VFSCache localCache = vfsCache;
         if (localCache != null) {
             return localCache.addFont(is);
@@ -53,8 +105,7 @@ public class BDJLoader {
         return null;
     }
 
-    /* called by org.dvb.ui.FontFactory */
-    public static File addFont(String fontFile) {
+    private static File addFontImpl(String fontFile) {
         VFSCache localCache = vfsCache;
         if (localCache != null) {
             return localCache.addFont(fontFile);



More information about the libbluray-devel mailing list