[Libreoffice-commits] online.git: 4 commits - android/app gtk/mobile.cpp ios/Mobile loleaflet/html loleaflet/src

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Feb 19 09:57:41 UTC 2019


 android/app/src/main/cpp/androidapp.cpp                                |   13 ++++++----
 android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java |    4 +--
 gtk/mobile.cpp                                                         |    6 ++--
 ios/Mobile/Document.mm                                                 |    6 ++--
 loleaflet/html/loleaflet.html.m4                                       |   12 ---------
 loleaflet/src/core/Socket.js                                           |    5 +++
 6 files changed, 21 insertions(+), 25 deletions(-)

New commits:
commit bce922e8fd50b5344b083aedfe04ed072661795b
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Tue Feb 19 10:54:51 2019 +0100
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Tue Feb 19 10:56:58 2019 +0100

    android: Various fixes to make the sending from the core to JS working.
    
    Change-Id: Idc22ccbae1effac9e2db5293703a768e033fd7e9

diff --git a/android/app/src/main/cpp/androidapp.cpp b/android/app/src/main/cpp/androidapp.cpp
index 89a703ceb..97000797a 100644
--- a/android/app/src/main/cpp/androidapp.cpp
+++ b/android/app/src/main/cpp/androidapp.cpp
@@ -64,14 +64,14 @@ static void send2JS(jclass mainActivityClz, jobject mainActivityObj, const std::
     {
         // The data needs to be an ArrayBuffer
         std::stringstream ss;
-        ss << "Base64ToArrayBuffer('";
+        ss << "{'base64data':'";
 
         Poco::Base64Encoder encoder(ss);
         encoder.rdbuf()->setLineLength(0); // unlimited
         encoder << std::string(buffer.data(), buffer.size());
         encoder.close();
 
-        ss << "')";
+        ss << "'}";
 
         js = ss.str();
     }
@@ -93,9 +93,8 @@ static void send2JS(jclass mainActivityClz, jobject mainActivityObj, const std::
                 data.push_back(ubufp[i]);
             }
         }
-        data.push_back(0);
 
-        js = std::string(data.data(), data.size());
+        js = "{'data':'" + std::string(data.data(), data.size()) + "'}";
     }
 
     std::string subjs = js.substr(0, std::min(std::string::size_type(SHOW_JS_MAXLEN), js.length()));
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
index 564df1911..88601d0be 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
@@ -181,7 +181,7 @@ public class MainActivity extends AppCompatActivity {
         mWebView.post(new Runnable() {
             public void run() {
                 Log.i(TAG,"Forwarding to the WebView: " + message);
-                mWebView.loadUrl("javascript:window.TheFakeWebSocket.onmessage({'data': '" + message + "'});");
+                mWebView.loadUrl("javascript:window.TheFakeWebSocket.onmessage(" + message + ");");
             }
         });
     }
diff --git a/gtk/mobile.cpp b/gtk/mobile.cpp
index 929e07d17..b2c346f7c 100644
--- a/gtk/mobile.cpp
+++ b/gtk/mobile.cpp
@@ -58,11 +58,11 @@ static void send2JS(const std::vector<char>& buffer)
     if (newline != nullptr)
     {
         // The data needs to be an ArrayBuffer
-        js = "window.TheFakeWebSocket.onmessage({'data': Base64ToArrayBuffer('";
+        js = "window.TheFakeWebSocket.onmessage({'base64data':'";
         gchar *base64 = g_base64_encode((const guchar*)buffer.data(), buffer.size());
         js = js + std::string(base64);
         g_free(base64);
-        js = js + "')});";
+        js = js + "'});";
     }
     else
     {
@@ -84,7 +84,7 @@ static void send2JS(const std::vector<char>& buffer)
         }
         data.push_back(0);
 
-        js = "window.TheFakeWebSocket.onmessage({'data': '";
+        js = "window.TheFakeWebSocket.onmessage({'data':'";
         js = js + std::string(buffer.data(), buffer.size());
         js = js + "'});";
     }
diff --git a/ios/Mobile/Document.mm b/ios/Mobile/Document.mm
index 70d130d64..804ba65d2 100644
--- a/ios/Mobile/Document.mm
+++ b/ios/Mobile/Document.mm
@@ -82,9 +82,9 @@
     const char *newline = (const char *)memchr(buffer, '\n', length);
     if (newline != nullptr) {
         // The data needs to be an ArrayBuffer
-        js = @"window.TheFakeWebSocket.onmessage({'data': Base64ToArrayBuffer('";
+        js = @"window.TheFakeWebSocket.onmessage({'base64data':'";
         js = [js stringByAppendingString: [[NSData dataWithBytes:buffer length:length] base64EncodedStringWithOptions:0]];
-        js = [js stringByAppendingString:@"')});"];
+        js = [js stringByAppendingString:@"'});"];
         NSString *subjs = [js substringToIndex:std::min(100ul, js.length)];
         if (subjs.length < js.length)
             subjs = [subjs stringByAppendingString:@"..."];
@@ -116,7 +116,7 @@
         }
         data.push_back(0);
 
-        js = @"window.TheFakeWebSocket.onmessage({'data': '";
+        js = @"window.TheFakeWebSocket.onmessage({'data':'";
         js = [js stringByAppendingString:[NSString stringWithUTF8String:data.data()]];
         js = [js stringByAppendingString:@"'});"];
 
diff --git a/loleaflet/html/loleaflet.html.m4 b/loleaflet/html/loleaflet.html.m4
index f43dd488f..a8233ba82 100644
--- a/loleaflet/html/loleaflet.html.m4
+++ b/loleaflet/html/loleaflet.html.m4
@@ -12,7 +12,7 @@ define([_foreachq],[ifelse([$#],[3],[],[define([$1],[$4])$2[]$0([$1],[$2],shift(
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 
 <script>
-dnl# Define MOBILEAPP as true if this is either for the iOS app or for the gtk+ "app" testbed
+dnl# Define MOBILEAPP as true if this is either for the iOS app, Android app or for the gtk+ "app" testbed
 define([MOBILEAPP],[])
 ifelse(IOSAPP,[true],[define([MOBILEAPP],[true])])
 ifelse(GTKAPP,[true],[define([MOBILEAPP],[true])])
@@ -31,16 +31,6 @@ ifelse(MOBILEAPP,[],
   };
   window.addEventListener('message', PostMessageReadyListener, false);
 )dnl
-
-var Base64ToArrayBuffer = function(base64Str) {
-  var binStr = atob(base64Str);
-  var ab = new ArrayBuffer(binStr.length);
-  var bv = new Uint8Array(ab);
-  for (var i = 0, l = binStr.length; i < l; i++) {
-    bv[[i]] = binStr.charCodeAt(i);
-  }
-  return ab;
-}
 </script>
 
 ifelse(MOBILEAPP,[true],
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 19c49ddef..649dcddfd 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -241,7 +241,10 @@ L.Socket = L.Class.extend({
 	_onMessage: function (e) {
 		var imgBytes, index, textMsg;
 
-		if (typeof (e.data) === 'string') {
+		if (typeof(e.base64data) === 'string') {
+			textMsg = atob(e.base64data);
+		}
+		else if (typeof (e.data) === 'string') {
 			textMsg = e.data;
 		}
 		else if (typeof (e.data) === 'object') {
commit a3226c108c239e3b0a2d0f891ed9fd11bc381e22
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Tue Feb 19 09:21:08 2019 +0100
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Tue Feb 19 10:56:58 2019 +0100

    android: Don't split the base64 encoded string to separate lines.
    
    Change-Id: Ie307f123bd2eec708adff581481d12babd1867ec

diff --git a/android/app/src/main/cpp/androidapp.cpp b/android/app/src/main/cpp/androidapp.cpp
index 96bc57ae4..89a703ceb 100644
--- a/android/app/src/main/cpp/androidapp.cpp
+++ b/android/app/src/main/cpp/androidapp.cpp
@@ -67,6 +67,7 @@ static void send2JS(jclass mainActivityClz, jobject mainActivityObj, const std::
         ss << "Base64ToArrayBuffer('";
 
         Poco::Base64Encoder encoder(ss);
+        encoder.rdbuf()->setLineLength(0); // unlimited
         encoder << std::string(buffer.data(), buffer.size());
         encoder.close();
 
commit a9fc9ee63ac6557ba3400145d6862850b6cb832e
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Tue Feb 19 09:13:56 2019 +0100
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Tue Feb 19 10:56:58 2019 +0100

    android: Cannot read the assets directly, use the unpack instead.
    
    Change-Id: I89818b122757b0f77a71c68e67cb2a1a27f2c0fb

diff --git a/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
index a2027d611..564df1911 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
@@ -124,7 +124,7 @@ public class MainActivity extends AppCompatActivity {
         String cacheDir = getApplication().getCacheDir().getAbsolutePath();
         String apkFile = getApplication().getPackageResourcePath();
 
-        String urlToLoad = "file:///assets/hello-world.odt";
+        String urlToLoad = "file://" + dataDir + "/hello-world.odt";
 
         createLOOLWSD(dataDir, cacheDir, apkFile, assetManager, urlToLoad);
 
commit 91280ea90565dcbd81e77f3ed74e2ac2039a91f4
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Mon Feb 18 13:38:19 2019 +0100
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Tue Feb 19 10:56:58 2019 +0100

    android: Need the the JavaVM in LibreOfficeKit too.
    
    Change-Id: Ice4a25be0e6eb8a2aa8e571bd22847e5fda1e8a2

diff --git a/android/app/src/main/cpp/androidapp.cpp b/android/app/src/main/cpp/androidapp.cpp
index a1d393e07..96bc57ae4 100644
--- a/android/app/src/main/cpp/androidapp.cpp
+++ b/android/app/src/main/cpp/androidapp.cpp
@@ -20,7 +20,9 @@
 #include <Protocol.hpp>
 #include <Util.hpp>
 
-#include "Poco/Base64Encoder.h"
+#include <osl/detail/android-bootstrap.h>
+
+#include <Poco/Base64Encoder.h>
 
 const int SHOW_JS_MAXLEN = 70;
 
@@ -35,6 +37,7 @@ static JavaVM* javaVM = nullptr;
 extern "C" JNIEXPORT jint JNICALL
 JNI_OnLoad(JavaVM* vm, void*) {
     javaVM = vm;
+    libreofficekit_set_javavm(vm);
 
     JNIEnv* env;
     if (vm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK) {


More information about the Libreoffice-commits mailing list