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 bce922e8fd.

Change-Id: I5d2ee19058261c7612d36014181f509604c8acde
This commit is contained in:
Jan Holesovsky
2019-02-19 23:56:59 +01:00
parent 14e998723f
commit 4f5e262344
6 changed files with 23 additions and 15 deletions

View File

@ -64,14 +64,14 @@ static void send2JS(jclass mainActivityClz, jobject mainActivityObj, const std::
{ {
// The data needs to be an ArrayBuffer // The data needs to be an ArrayBuffer
std::stringstream ss; std::stringstream ss;
ss << "{'base64data':'"; ss << "Base64ToArrayBuffer('";
Poco::Base64Encoder encoder(ss); Poco::Base64Encoder encoder(ss);
encoder.rdbuf()->setLineLength(0); // unlimited encoder.rdbuf()->setLineLength(0); // unlimited
encoder << std::string(buffer.data(), buffer.size()); encoder << std::string(buffer.data(), buffer.size());
encoder.close(); encoder.close();
ss << "'}"; ss << "')";
js = ss.str(); js = ss.str();
} }
@ -93,8 +93,9 @@ static void send2JS(jclass mainActivityClz, jobject mainActivityObj, const std::
data.push_back(ubufp[i]); 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())); std::string subjs = js.substr(0, std::min(std::string::size_type(SHOW_JS_MAXLEN), js.length()));

View File

@ -181,7 +181,7 @@ public class MainActivity extends AppCompatActivity {
mWebView.post(new Runnable() { mWebView.post(new Runnable() {
public void run() { public void run() {
Log.i(TAG,"Forwarding to the WebView: " + message); Log.i(TAG,"Forwarding to the WebView: " + message);
mWebView.loadUrl("javascript:window.TheFakeWebSocket.onmessage(" + message + ");"); mWebView.loadUrl("javascript:window.TheFakeWebSocket.onmessage({'data': '" + message + "'});");
} }
}); });
} }

View File

@ -58,11 +58,11 @@ static void send2JS(const std::vector<char>& buffer)
if (newline != nullptr) if (newline != nullptr)
{ {
// The data needs to be an ArrayBuffer // 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()); gchar *base64 = g_base64_encode((const guchar*)buffer.data(), buffer.size());
js = js + std::string(base64); js = js + std::string(base64);
g_free(base64); g_free(base64);
js = js + "'});"; js = js + "')});";
} }
else else
{ {
@ -84,7 +84,7 @@ static void send2JS(const std::vector<char>& buffer)
} }
data.push_back(0); data.push_back(0);
js = "window.TheFakeWebSocket.onmessage({'data':'"; js = "window.TheFakeWebSocket.onmessage({'data': '";
js = js + std::string(buffer.data(), buffer.size()); js = js + std::string(buffer.data(), buffer.size());
js = js + "'});"; js = js + "'});";
} }

View File

@ -82,9 +82,9 @@
const char *newline = (const char *)memchr(buffer, '\n', length); const char *newline = (const char *)memchr(buffer, '\n', length);
if (newline != nullptr) { if (newline != nullptr) {
// The data needs to be an ArrayBuffer // 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: [[NSData dataWithBytes:buffer length:length] base64EncodedStringWithOptions:0]];
js = [js stringByAppendingString:@"'});"]; js = [js stringByAppendingString:@"')});"];
NSString *subjs = [js substringToIndex:std::min(100ul, js.length)]; NSString *subjs = [js substringToIndex:std::min(100ul, js.length)];
if (subjs.length < js.length) if (subjs.length < js.length)
subjs = [subjs stringByAppendingString:@"..."]; subjs = [subjs stringByAppendingString:@"..."];
@ -116,7 +116,7 @@
} }
data.push_back(0); data.push_back(0);
js = @"window.TheFakeWebSocket.onmessage({'data':'"; js = @"window.TheFakeWebSocket.onmessage({'data': '";
js = [js stringByAppendingString:[NSString stringWithUTF8String:data.data()]]; js = [js stringByAppendingString:[NSString stringWithUTF8String:data.data()]];
js = [js stringByAppendingString:@"'});"]; js = [js stringByAppendingString:@"'});"];

View File

@ -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"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<script> <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],[]) define([MOBILEAPP],[])
ifelse(IOSAPP,[true],[define([MOBILEAPP],[true])]) ifelse(IOSAPP,[true],[define([MOBILEAPP],[true])])
ifelse(GTKAPP,[true],[define([MOBILEAPP],[true])]) ifelse(GTKAPP,[true],[define([MOBILEAPP],[true])])
@ -31,6 +31,16 @@ ifelse(MOBILEAPP,[],
}; };
window.addEventListener('message', PostMessageReadyListener, false); window.addEventListener('message', PostMessageReadyListener, false);
)dnl )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> </script>
ifelse(MOBILEAPP,[true], ifelse(MOBILEAPP,[true],

View File

@ -241,10 +241,7 @@ L.Socket = L.Class.extend({
_onMessage: function (e) { _onMessage: function (e) {
var imgBytes, index, textMsg; var imgBytes, index, textMsg;
if (typeof(e.base64data) === 'string') { if (typeof (e.data) === 'string') {
textMsg = atob(e.base64data);
}
else if (typeof (e.data) === 'string') {
textMsg = e.data; textMsg = e.data;
} }
else if (typeof (e.data) === 'object') { else if (typeof (e.data) === 'object') {