tdf#126968: Implement "Save as PDF" in the iOS app

For now, add an entry "Save as PDF" to the File menu in the iOS app.
Handle in an iOS-specific way in ChildSession::downloadAs(). The PDF
is saved in the app's document directory on the device. The name of
the PDF is the basename of the document being edited with the "pdf"
extension.

Change-Id: Ib0059a86b03b978996eb4cadf230ba7f0abcba62
Reviewed-on: https://gerrit.libreoffice.org/77961
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Tested-by: Tor Lillqvist <tml@collabora.com>
diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index fadbca1..6d7751f 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -879,6 +879,15 @@
        filterOptions += std::string(",Watermark=") + getWatermarkText() + std::string("WATERMARKEND");
    }

#ifdef IOS
    NSArray<NSString *> *pathComponents = [[NSURL URLWithString:[NSString stringWithUTF8String:getDocURL().c_str()]] pathComponents];
    NSString *baseName = [[pathComponents lastObject] stringByDeletingPathExtension];
    NSURL *documentDirectory = [NSFileManager.defaultManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask][0];
    NSURL *pdfURL = [documentDirectory URLByAppendingPathComponent:[baseName stringByAppendingString:@".pdf"]];
    getLOKitDocument()->saveAs([[pdfURL absoluteString] UTF8String],
                               format.empty() ? nullptr : format.c_str(),
                               filterOptions.empty() ? nullptr : filterOptions.c_str());
#else
    // The file is removed upon downloading.
    const std::string tmpDir = FileUtil::createRandomDir(JAILED_DOCUMENT_ROOT);
    // Prevent user inputting anything funny here.
@@ -898,6 +907,7 @@

    sendTextFrame("downloadas: jail=" + _jailId + " dir=" + tmpDir + " name=" + name +
                  " port=" + std::to_string(ClientPortNumber) + " id=" + id);
#endif
    return true;
}

diff --git a/loleaflet/src/control/Control.Menubar.js b/loleaflet/src/control/Control.Menubar.js
index 41120cf..c71fee4 100644
--- a/loleaflet/src/control/Control.Menubar.js
+++ b/loleaflet/src/control/Control.Menubar.js
@@ -27,6 +27,7 @@
					{name: _('Word 2003 Document (.doc)'), id: 'downloadas-doc', type: 'action'},
					{name: _('Word Document (.docx)'), id: 'downloadas-docx', type: 'action'},
					{name: _('Rich Text (.rtf)'), id: 'downloadas-rtf', type: 'action'}]},
				{name: _('Save as PDF'), id: 'downloadas-pdf', mobileapp: true, type: 'action'},
				{name: _('Sign document'), id: 'signdocument', type: 'action'},
				{type: 'separator'},
				{name: _('Close document'), id: 'closedocument', type: 'action'}
@@ -250,6 +251,7 @@
					{name: _('ODF presentation (.odp)'), id: 'downloadas-odp', type: 'action'},
					{name: _('PowerPoint 2003 Presentation (.ppt)'), id: 'downloadas-ppt', type: 'action'},
					{name: _('PowerPoint Presentation (.pptx)'), id: 'downloadas-pptx', type: 'action'}]},
				{name: _('Save as PDF'), id: 'downloadas-pdf', mobileapp: true, type: 'action'},
				{type: 'separator'},
				{name: _('Close document'), id: 'closedocument', type: 'action'}
			]},
@@ -338,6 +340,7 @@
					{name: _('ODF spreadsheet (.ods)'), id: 'downloadas-ods', type: 'action'},
					{name: _('Excel 2003 Spreadsheet (.xls)'), id: 'downloadas-xls', type: 'action'},
					{name: _('Excel Spreadsheet (.xlsx)'), id: 'downloadas-xlsx', type: 'action'}]},
				{name: _('Save as PDF'), id: 'downloadas-pdf', mobileapp: true, type: 'action'},
				{type: 'separator'},
				{name: _('Close document'), id: 'closedocument', type: 'action'}
			]},
@@ -996,6 +999,9 @@
				if (menu[i].mobileapp == false && window.ThisIsAMobileApp) {
					continue;
				}
				if (menu[i].mobileapp == true && !window.ThisIsAMobileApp) {
					continue;
				}
				var ulItem = L.DomUtil.create('ul', '', liItem);
				var subitemList = this._createMenu(menu[i].menu);
				if (!subitemList.length) {
diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js
index 06563be..f4ffa86 100644
--- a/loleaflet/src/control/Toolbar.js
+++ b/loleaflet/src/control/Toolbar.js
@@ -72,7 +72,8 @@
			options = '';
		}

		this.showBusy(_('Downloading...'), false);
		if (!window.ThisIsAMobileApp)
			this.showBusy(_('Downloading...'), false);
		this._socket.sendMessage('downloadas ' +
			'name=' + encodeURIComponent(name) + ' ' +
			'id=' + id + ' ' +