mirror of
https://github.com/LibreOffice/online.git
synced 2025-08-16 17:42:05 +00:00
android: Various fixes to make the sending from the core to JS working.
Change-Id: Idc22ccbae1effac9e2db5293703a768e033fd7e9
This commit is contained in:
@ -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()));
|
||||
|
@ -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 + ");");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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 + "'});";
|
||||
}
|
||||
|
@ -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:@"'});"];
|
||||
|
||||
|
@ -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],
|
||||
|
@ -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') {
|
||||
|
Reference in New Issue
Block a user