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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Feb 19 23:38:44 UTC 2019


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

New commits:
commit 354c2ce2a366073a4fbfe2cb72e08b6a30fc4a4f
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Wed Feb 20 00:34:19 2019 +0100
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Wed Feb 20 00:38:16 2019 +0100

    android: Fix passing of the base64-encoded messages.
    
    Change-Id: I8519bff3ec96d7a2acf25ef4b5258b5493befd4f

diff --git a/android/app/src/main/cpp/androidapp.cpp b/android/app/src/main/cpp/androidapp.cpp
index 89a703ceb..a54ff86fc 100644
--- a/android/app/src/main/cpp/androidapp.cpp
+++ b/android/app/src/main/cpp/androidapp.cpp
@@ -79,6 +79,7 @@ static void send2JS(jclass mainActivityClz, jobject mainActivityObj, const std::
     {
         const unsigned char *ubufp = (const unsigned char *)buffer.data();
         std::vector<char> data;
+        data.push_back('\'');
         for (int i = 0; i < buffer.size(); i++)
         {
             if (ubufp[i] < ' ' || ubufp[i] == '\'' || ubufp[i] == '\\')
@@ -93,7 +94,7 @@ static void send2JS(jclass mainActivityClz, jobject mainActivityObj, const std::
                 data.push_back(ubufp[i]);
             }
         }
-        data.push_back(0);
+        data.push_back('\'');
 
         js = std::string(data.data(), data.size());
     }
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..c1eea24cf 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({'data':" + message + "});");
             }
         });
     }
commit 4f5e262344e76eca3791b2602afa4c542b37e1e4
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Tue Feb 19 23:56:59 2019 +0100
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Wed Feb 20 00:38:16 2019 +0100

    Revert "android: Various fixes to make the sending from the core to JS..."
    
    Lets leave this optimization for later, this is incomplete, and does not
    fix the problem which it was originally supposed to address.
    
    This reverts commit bce922e8fd50b5344b083aedfe04ed072661795b.
    
    Change-Id: I5d2ee19058261c7612d36014181f509604c8acde

diff --git a/android/app/src/main/cpp/androidapp.cpp b/android/app/src/main/cpp/androidapp.cpp
index 97000797a..89a703ceb 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 << "{'base64data':'";
+        ss << "Base64ToArrayBuffer('";
 
         Poco::Base64Encoder encoder(ss);
         encoder.rdbuf()->setLineLength(0); // unlimited
         encoder << std::string(buffer.data(), buffer.size());
         encoder.close();
 
-        ss << "'}";
+        ss << "')";
 
         js = ss.str();
     }
@@ -93,8 +93,9 @@ static void send2JS(jclass mainActivityClz, jobject mainActivityObj, const std::
                 data.push_back(ubufp[i]);
             }
         }
+        data.push_back(0);
 
-        js = "{'data':'" + std::string(data.data(), data.size()) + "'}";
+        js = 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 88601d0be..564df1911 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(" + message + ");");
+                mWebView.loadUrl("javascript:window.TheFakeWebSocket.onmessage({'data': '" + message + "'});");
             }
         });
     }
diff --git a/gtk/mobile.cpp b/gtk/mobile.cpp
index b2c346f7c..929e07d17 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({'base64data':'";
+        js = "window.TheFakeWebSocket.onmessage({'data': Base64ToArrayBuffer('";
         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 804ba65d2..70d130d64 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({'base64data':'";
+        js = @"window.TheFakeWebSocket.onmessage({'data': Base64ToArrayBuffer('";
         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 a8233ba82..f43dd488f 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, Android app or for the gtk+ "app" testbed
+dnl# Define MOBILEAPP as true if this is either for the iOS app or for the gtk+ "app" testbed
 define([MOBILEAPP],[])
 ifelse(IOSAPP,[true],[define([MOBILEAPP],[true])])
 ifelse(GTKAPP,[true],[define([MOBILEAPP],[true])])
@@ -31,6 +31,16 @@ 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 649dcddfd..19c49ddef 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -241,10 +241,7 @@ L.Socket = L.Class.extend({
 	_onMessage: function (e) {
 		var imgBytes, index, textMsg;
 
-		if (typeof(e.base64data) === 'string') {
-			textMsg = atob(e.base64data);
-		}
-		else if (typeof (e.data) === 'string') {
+		if (typeof (e.data) === 'string') {
 			textMsg = e.data;
 		}
 		else if (typeof (e.data) === 'object') {


More information about the Libreoffice-commits mailing list