[Libreoffice-commits] online.git: 3 commits - loleaflet/html loleaflet/js loleaflet/Makefile.am loleaflet/src

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Sep 7 14:38:58 UTC 2018


 loleaflet/Makefile.am            |   13 ++++++-
 loleaflet/html/loleaflet.html.m4 |   41 ++++++++++++++++++----
 loleaflet/js/global.js           |    8 +++-
 loleaflet/js/main.js             |    4 +-
 loleaflet/src/core/Socket.js     |   71 ++++++++++++++++++++++++++++-----------
 5 files changed, 107 insertions(+), 30 deletions(-)

New commits:
commit 49da3c03a619d2983a96cac531c2fcac79ef9ffd
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Fri Sep 7 16:40:18 2018 +0300
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Fri Sep 7 17:37:54 2018 +0300

    Move a few lines of code into the else branch they are relevant for
    
    Change-Id: If0ce5236f1cd0daae6b213ed19d57820d25206e0

diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index ed799b3bd..cd6744f08 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -56,17 +56,17 @@ L.Socket = L.Class.extend({
 		if (map.options.permission) {
 			map.options.docParams['permission'] = map.options.permission;
 		}
-		var wopiSrc = '';
-		if (map.options.wopiSrc != '') {
-			wopiSrc = '?WOPISrc=' + map.options.wopiSrc + '&compat=/ws';
-		}
-
 		if (this.socket) {
 			this.close();
 		}
 		if (window.ThisIsTheiOSApp) {
 			this.socket = new FakeWebSocket();
 		} else {
+			var wopiSrc = '';
+			if (map.options.wopiSrc != '') {
+				wopiSrc = '?WOPISrc=' + map.options.wopiSrc + '&compat=/ws';
+			}
+
 			try {
 				var websocketURI = map.options.server + '/lool/' + encodeURIComponent(map.options.doc + '?' + $.param(map.options.docParams)) + '/ws' + wopiSrc;
 				this.socket = new WebSocket(websocketURI);
commit fb7cc57b0fdb3373b9f46c6a0bb1f8c2a22c9c74
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Fri Sep 7 16:27:00 2018 +0300
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Fri Sep 7 17:37:54 2018 +0300

    Work in Progress: Check window.ThisIsTheiOSApp and behave accordingly
    
    First steps to modify behaviour in the app case. No query parameters
    or WebSocket messages in that case.
    
    Change-Id: I170d46830bb940c5164af3f62b873672373d8f17

diff --git a/loleaflet/html/loleaflet.html.m4 b/loleaflet/html/loleaflet.html.m4
index f41d80c4f..2ae7c4a49 100644
--- a/loleaflet/html/loleaflet.html.m4
+++ b/loleaflet/html/loleaflet.html.m4
@@ -1,3 +1,4 @@
+dnl -*- Mode: HTML -*-x
 changequote([,])dnl
 dnl# foreachq(x, `item_1, item_2, ..., item_n', stmt)
 dnl# quoted list, alternate improved version
@@ -17,6 +18,10 @@ define([_foreachq],[ifelse([$#],[3],[],[define([$1],[$4])$2[]$0([$1],[$2],shift(
   var PostMessageReadyListener = function(e) {
     var msg = JSON.parse(e.data);
     if (msg.MessageId === 'Host_PostmessageReady') {
+      if (window.ThisIsTheiOSApp) {
+        // Just for debugging to see that we got it
+        window.webkit.messageHandlers.lool.postMessage('got Host_PostmessageReady!');
+      }
       window.WOPIPostmessageReady = true;
       window.removeEventListener('message', PostMessageReadyListener, false);
     }
@@ -116,18 +121,40 @@ ifelse(IOSAPP,[true],
     </div>
 
     <script>
-      window.host = '%HOST%';
+ifelse(IOSAPP,[true],
+     [window.host = '';
+      window.accessToken = '';
+      window.accessTokenTTL = '';
+      window.accessHeader = '';
+      window.loleafletLogging = 'true';
+      window.outOfFocusTimeoutSecs = 1000000;
+      window.idleTimeoutSecs = 1000000;],
+     [window.host = '%HOST%';
       window.accessToken = '%ACCESS_TOKEN%';
       window.accessTokenTTL = '%ACCESS_TOKEN_TTL%';
       window.accessHeader = '%ACCESS_HEADER%';
       window.loleafletLogging = '%LOLEAFLET_LOGGING%';
       window.outOfFocusTimeoutSecs = %OUT_OF_FOCUS_TIMEOUT_SECS%;
-      window.idleTimeoutSecs = %IDLE_TIMEOUT_SECS%;
+      window.idleTimeoutSecs = %IDLE_TIMEOUT_SECS%;])
     </script>
-ifelse(DEBUG,[true],foreachq([fileJS],[LOLEAFLET_JS],
-[    <script src="/loleaflet/%VERSION%/fileJS"></script>
-]),
-[    <script src="/loleaflet/%VERSION%/bundle.js"></script>
-])dnl
+  <script>
+ifelse(IOSAPP,[true],
+  [window.ThisIsTheiOSApp = true;],
+  [window.ThisIsTheiOSApp = false;]
+)
+  </script>
+
+ifelse(IOSAPP,[true],
+  ifelse(DEBUG,[true],foreachq([fileJS],[LOLEAFLET_JS],
+  [    <script src="fileJS"></script>
+  ]),
+  [    <script src="bundle.js"></script>
+  ]),
+  ifelse(DEBUG,[true],foreachq([fileJS],[LOLEAFLET_JS],
+  [    <script src="/loleaflet/%VERSION%/fileJS"></script>
+  ]),
+  [    <script src="/loleaflet/%VERSION%/bundle.js"></script>
+  ])
+)dnl
     <!--%BRANDING_JS%--> <!-- logo onclick handler -->
 </body></html>
diff --git a/loleaflet/js/main.js b/loleaflet/js/main.js
index e53a3117f..4f14a26bd 100644
--- a/loleaflet/js/main.js
+++ b/loleaflet/js/main.js
@@ -25,10 +25,10 @@ var revHistoryEnabled = getParameterByName('revisionhistory');
 var alwaysActive = getParameterByName('alwaysactive');
 // Loleaflet Debug mode
 var debugMode = getParameterByName('debug');
-if (wopiSrc === '' && filePath === '') {
+if (wopiSrc === '' && filePath === '' && !window.ThisIsTheiOSApp) {
 	vex.dialog.alert(errorMessages.wrongwopisrc);
 }
-if (host === '') {
+if (host === '' && !window.ThisIsTheiOSApp) {
 	vex.dialog.alert(errorMessages.emptyhosturl);
 }
 
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 6eaeace1b..ed799b3bd 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -4,6 +4,35 @@
  */
 
 /* global _ vex $ errorMessages Uint8Array brandProductName brandProductFAQURL */
+
+window.fakeWebSocketCounter = 0;
+function FakeWebSocket() {
+	this.binaryType = 'arraybuffer';
+	this.bufferedAmount = 0;
+	this.extensions = '';
+	this.protocol = '';
+	this.readyState = 0;
+	this.id = window.fakeWebSocketCounter++;
+	console.log('>>>>>> Created FakeWebSocket#' + this.id);
+	this.onclose = function() {
+	};
+	this.onerror = function() {
+	};
+	this.onmessage = function() {
+	};
+	this.onopen = function() {
+	};
+}
+
+FakeWebSocket.prototype.close = function() {
+	console.log('>>>>>> Closing FakeWebSocket#' + this.id);
+}
+
+FakeWebSocket.prototype.send = function(data) {
+	console.log('>>>>>> Sending data on FakeWebSocket#' + this.id + ': "' + data + '"');
+	window.webkit.messageHandlers.lool.postMessage(data, '*');
+}
+
 L.Socket = L.Class.extend({
 	ProtocolVersionNumber: '0.1',
 	ReconnectCount: 0,
@@ -32,22 +61,26 @@ L.Socket = L.Class.extend({
 			wopiSrc = '?WOPISrc=' + map.options.wopiSrc + '&compat=/ws';
 		}
 
-		var websocketURI = map.options.server + '/lool/' + encodeURIComponent(map.options.doc + '?' + $.param(map.options.docParams)) + '/ws' + wopiSrc;
-		try {
-			if (this.socket) {
-				this.close();
+		if (this.socket) {
+			this.close();
+		}
+		if (window.ThisIsTheiOSApp) {
+			this.socket = new FakeWebSocket();
+		} else {
+			try {
+				var websocketURI = map.options.server + '/lool/' + encodeURIComponent(map.options.doc + '?' + $.param(map.options.docParams)) + '/ws' + wopiSrc;
+				this.socket = new WebSocket(websocketURI);
+			} catch (e) {
+				// On IE 11 there is a limitation on the number of WebSockets open to a single domain (6 by default and can go to 128).
+				// Detect this and hint the user.
+				var msgHint = '';
+				var isIE11 = !!window.MSInputMethodContext && !!document.documentMode; // https://stackoverflow.com/questions/21825157/internet-explorer-11-detection
+				if (isIE11)
+					msgHint = _('IE11 has reached its maximum number of connections. Please see this document to increase this limit if needed: https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/general-info/ee330736(v=vs.85)#websocket-maximum-server-connections');
+
+				this._map.fire('error', {msg: _('Oops, there is a problem connecting to LibreOffice Online : ').replace('LibreOffice Online', (typeof brandProductName !== 'undefined' ? brandProductName : 'LibreOffice Online')) + e + msgHint, cmd: 'socket', kind: 'failed', id: 3});
+				return;
 			}
-			this.socket = new WebSocket(websocketURI);
-		} catch (e) {
-			// On IE 11 there is a limitation on the number of WebSockets open to a single domain (6 by default and can go to 128).
-			// Detect this and hint the user.
-			var msgHint = '';
-			var isIE11 = !!window.MSInputMethodContext && !!document.documentMode; // https://stackoverflow.com/questions/21825157/internet-explorer-11-detection
-			if (isIE11)
-				msgHint = _('IE11 has reached its maximum number of connections. Please see this document to increase this limit if needed: https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/general-info/ee330736(v=vs.85)#websocket-maximum-server-connections');
-
-			this._map.fire('error', {msg: _('Oops, there is a problem connecting to LibreOffice Online : ').replace('LibreOffice Online', (typeof brandProductName !== 'undefined' ? brandProductName : 'LibreOffice Online')) + e + msgHint, cmd: 'socket', kind: 'failed', id: 3});
-			return;
 		}
 
 		this.socket.onerror = L.bind(this._onSocketError, this);
commit e713d8c3237d5219a15a405020a16f3f6cf2d8a7
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Fri Sep 7 16:17:37 2018 +0300
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Fri Sep 7 16:43:39 2018 +0300

    No l10n in the iOS app for now

diff --git a/loleaflet/Makefile.am b/loleaflet/Makefile.am
index 922a6242d..a1deb0f78 100644
--- a/loleaflet/Makefile.am
+++ b/loleaflet/Makefile.am
@@ -7,7 +7,14 @@
 DRAW_VERSION=0.2.4
 
 L10N_PO = $(wildcard $(srcdir)/po/*.po)
+
+# It would be nice to have l10n also in the iOS app, but have to
+# skip for now as that l10n-for-node code seems to always want to use
+# HTTP to load the message catalog .json files.
+
+if !ENABLE_IOSAPP
 L10N_JSON = $(patsubst $(srcdir)/po/%.po,$(builddir)/dist/l10n/%.json,$(L10N_PO))
+endif
 
 JQUERY_UI_IMAGE_PATH = node_modules/jquery-ui/themes/ui-lightness/images
 JQUERY_UI_IMAGES = $(wildcard $(JQUERY_UI_IMAGE_PATH)/*.png)
@@ -80,12 +87,16 @@ NODE_MODULES_JS =\
 	node_modules/timeago/jquery.timeago.js \
 	node_modules/autolinker/dist/Autolinker.js \
 	node_modules/json-js/json2.js \
-	node_modules/l10n-for-node/l10n.js \
 	node_modules/select2/dist/js/select2.js \
 	node_modules/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.js \
 	node_modules/vex-js/js/vex.js \
 	node_modules/vex-js/js/vex.dialog.js
 
+if !ENABLE_IOSAPP
+NODE_MODULES_JS +=\
+	node_modules/l10n-for-node/l10n.js
+endif
+
 NODE_MODULES_JS_SRC = $(patsubst %.js,$(builddir)/%.js,$(NODE_MODULES_JS))
 NODE_MODULES_JS_DST = $(patsubst %.js,$(builddir)/dist/%.js,$(NODE_MODULES_JS))
 
diff --git a/loleaflet/js/global.js b/loleaflet/js/global.js
index 730077232..c8d540cc8 100644
--- a/loleaflet/js/global.js
+++ b/loleaflet/js/global.js
@@ -29,7 +29,13 @@ global.getParameterByName = function (name) {
 };
 
 global._ = function (string) {
-	return string.toLocaleString();
+	// In the iOS case we can't use the stuff from l10n-for-node, as that assumes HTTP.
+	// So bail out for now.
+	if (window.ThisIsTheiOSApp) {
+		return string;
+	} else {
+		return string.toLocaleString();
+	}
 };
 
 }(window));


More information about the Libreoffice-commits mailing list