Commit 807b1fe0 authored by Roque's avatar Roque

Officejs: migrate from cache manifest to service worker

Drop appcache use in all OfficeJS application

See merge request !1091
parents 44a13278 cf477758
Pipeline #9439 passed with stage
......@@ -9,7 +9,7 @@
<script src="${latest_version}/rsvp.js"></script>
<script src="${latest_version}/renderjs.js"></script>
<script src="${latest_version}/jiodev.js"></script>
<script src="jio_appcachestorage.js"></script>
<script src="jio_precachestorage.js"></script>
<script src="gadget_officejs_bootloader.js"></script>
</head>
......
......@@ -36,7 +36,7 @@ var repair = false;
}
},
remote_sub_storage: {
type: "appcache",
type: "precache",
manifest: gadget.props.cache_file,
version: gadget.props.version_url,
take_installer: true
......@@ -176,4 +176,4 @@ var repair = false;
return;
});
}(window, document, RSVP, rJS, jIO, navigator, URL));
\ No newline at end of file
}(window, document, RSVP, rJS, jIO, navigator, URL));
/*jslint indent:2, maxlen: 80, nomen: true */
/*global jIO, RSVP, window, Rusha, Blob, URL, console */
(function (window, jIO, RSVP, Rusha, Blob, URL, console) {
"use strict";
var rusha = new Rusha();
function PreCacheStorage(spec) {
this._precache_manifest_script = spec.manifest;
this._take_installer = spec.take_installer || false;
this._origin_url = spec.origin_url !== undefined ?
spec.origin_url : window.location.href;
this._version = spec.version || "";
this._prefix = spec.prefix || "./";
this._documents = {};
// Harcoded here, find a better way.
if (this._take_installer) {
this._relative_url_list = [
this._prefix,
this._prefix + "gadget_officejs_bootloader.js",
this._prefix + "gadget_officejs_bootloader.html",
this._prefix + "gadget_officejs_bootloader_presentation.html",
this._prefix + "gadget_officejs_bootloader_presentation.js",
this._prefix + "gadget_officejs_bootloader_presentation.css",
this._prefix + "gadget_officejs_bootloader_serviceworker.js",
this._prefix + "gadget_erp5_nojqm.css",
this._prefix + "officejs_logo.png",
this._prefix + "jio_precachestorage.js"
];
} else {
this._relative_url_list = [this._prefix + "/"];
}
if (this._take_installer) {
this._version = 'app/';
}
this._version = this._prefix + this._version;
}
PreCacheStorage.prototype.get = function (id) {
if (this._documents.hasOwnProperty(id)) {
return this._documents[id];
}
throw new jIO.util.jIOError('can not find document : ' + id, 404);
};
PreCacheStorage.prototype.hasCapacity = function () {
return true;
};
PreCacheStorage.prototype.getAttachment = function (origin_url,
relative_url) {
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
type: "GET",
url: new URL(relative_url, origin_url),
dataType: "blob"
});
})
.push(function (result) {
return result.target.response;
});
};
PreCacheStorage.prototype.allAttachments = function (id) {
if (id === this._origin_url) {
var result = {}, i, len = this._relative_url_list.length;
for (i = 0; i < len; i += 1) {
result[this._relative_url_list[i]] = {};
}
return result;
}
return [];
};
PreCacheStorage.prototype.buildQuery = function () {
var result = [], id;
for (id in this._documents) {
if (this._documents.hasOwnProperty(id)) {
result.push({
'id': id,
'value': this._documents[id],
'doc': this._documents[id]
});
}
}
return result;
};
PreCacheStorage.prototype.repair = function () {
var storage = this, url;
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
type: "GET",
url: new URL(storage._precache_manifest_script,
new URL(storage._version, storage._origin_url))
});
})
.push(function (response) {
var base_manifest_text = response.target.responseText,
relative_url_list,
i,
hash = rusha.digestFromString(base_manifest_text +
response.target
.getResponseHeader("ETag"));
relative_url_list = Object.keys(JSON.parse(base_manifest_text));
storage._relative_url_list.push(storage._version);
storage._relative_url_list.push(storage._version +
storage._precache_manifest_script);
storage._documents[storage._origin_url] = {'hash': hash};
for (i = 0; i < relative_url_list.length; i += 1) {
url = relative_url_list[i];
if (url.includes('?')) {
throw new Error("It is not allow to cache urls with parameters." +
" url: " + url);
}
storage._relative_url_list.push(
storage._version + url
);
}
}, function (error) {
if (error.target.status === 404 && !error.message) {
error.message = "Couldn't get the precache manifest '" +
storage._precache_manifest_script + "'";
}
throw error;
});
};
jIO.addStorage('precache', PreCacheStorage);
}(window, jIO, RSVP, Rusha, Blob, URL, console));
......@@ -2,7 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Manifest" module="erp5.portal_type"/>
<global name="Web Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
......@@ -64,9 +64,7 @@
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>contributor/person_module/1</string>
</tuple>
<tuple/>
</value>
</item>
<item>
......@@ -75,13 +73,9 @@
<none/>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/plain</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_officejs_drive_app.appcache</string> </value>
<value> <string>jio_precachestorage.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -91,7 +85,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>gadget_officejs_drive_app_appcache</string> </value>
<value> <string>gadget_officejs_jio_precachestorage_js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
......@@ -99,7 +93,7 @@
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Manifest</string> </value>
<value> <string>Web Script</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
......@@ -107,128 +101,9 @@
<none/>
</value>
</item>
<item>
<key> <string>text_content</string> </key>
<value> <string>CACHE MANIFEST\n
# generated on Fri, 5 Sep 2017 16:00:33 +0900\n
# XXX + fonts\n
# images/ajax-loader.gif\n
CACHE:\n
font-awesome/font-awesome.css\n
font-awesome/font-awesome-webfont.eot\n
font-awesome/font-awesome-webfont.woff\n
font-awesome/font-awesome-webfont.woff2\n
font-awesome/font-awesome-webfont.ttf\n
font-awesome/font-awesome-webfont.svg\n
gadget_erp5_nojqm.css\n
jio_ojs_storage.js\n
gadget_erp5_global.js\n
URI.js\n
dygraph.js\n
handlebars.js\n
domsugar.js\n
jiodev.js\n
renderjs.js\n
rsvp.js\n
gadget_global.js\n
erp5_launcher_nojqm.js\n
gadget_officejs_router.js\n
gadget_erp5_router.html\n
gadget_erp5_router.js\n
gadget_officejs_liberator.html\n
gadget_officejs_liberator.js\n
gadget_jio.html\n
gadget_jio.js\n
gadget_translate.html\n
gadget_translate.js\n
gadget_translation.html\n
gadget_translation.js\n
gadget_translation_data.js\n
gadget_erp5_editor_panel.html\n
gadget_erp5_editor_panel.js\n
gadget_erp5_drive_app_panel.html\n
gadget_erp5_drive_app_panel.js\n
gadget_erp5_header.html\n
gadget_erp5_header.js\n
gadget_drive_app_jio.html\n
gadget_drive_app_jio.js\n
gadget_erp5_page_ojs_controller.html\n
gadget_erp5_page_ojs_controller.js\n
gadget_erp5_page_drive_app_add_document.html\n
gadget_erp5_page_drive_app_add_document.js\n
gadget_erp5_page_drive_app_configurator.html\n
gadget_erp5_page_drive_app_configurator.js\n
gadget_erp5_page_ojs_sync.html\n
gadget_erp5_page_ojs_sync.js\n
gadget_erp5_page_drive_app_document_list.html\n
gadget_erp5_page_drive_app_document_list.js\n
gadget_drive_app_configurator_access.html\n
gadget_drive_app_configurator_access.js\n
gadget_html5_input.html\n
gadget_html5_input.js\n
gadget_erp5_field_multicheckbox.html\n
gadget_erp5_field_multicheckbox.js\n
gadget_erp5_searchfield.html\n
gadget_erp5_searchfield.js\n
gadget_erp5_pt_form_list.html\n
gadget_erp5_pt_form_list.js\n
gadget_erp5_form.html\n
gadget_erp5_form.js\n
gadget_erp5_label_field.html\n
gadget_erp5_label_field.js\n
gadget_erp5_field_listbox.html\n
gadget_erp5_field_listbox.js\n
gadget_erp5_field_datetime.html\n
gadget_erp5_field_datetime.js\n
gadget_html5_element.html\n
gadget_html5_element.js\n
gadget_erp5_notification.html\n
gadget_erp5_notification.js\n
gadget_erp5_field_string.html\n
gadget_erp5_field_string.js\n
gadget_erp5_field_editor.html\n
gadget_erp5_field_editor.js\n
gadget_erp5_field_gadget.html\n
gadget_erp5_field_gadget.js\n
gadget_erp5_search_editor.html\n
gadget_erp5_search_editor.js\n
gadget_erp5_sort_editor.html\n
gadget_erp5_sort_editor.js\n
gadget_erp5_field_password.html\n
gadget_erp5_field_password.js\n
gadget_erp5_page_ojs_configurator.html\n
gadget_erp5_page_ojs_configurator.js\n
gadget_ojs_configurator_access.html\n
gadget_ojs_configurator_access.js\n
gadget_erp5_field_list.html\n
gadget_erp5_field_list.js\n
gadget_html5_select.html\n
gadget_html5_select.js\n
gadget_html5_textarea.html\n
gadget_html5_textarea.js\n
gadget_erp5_field_integer.html\n
gadget_erp5_field_integer.js\n
gadget_erp5_field_textarea.html\n
gadget_erp5_field_textarea.js\n
gadget_erp5_field_radio.html\n
gadget_erp5_field_radio.js\n
gadget_officejs_bootloader_serviceworker.js\n
gadget_erp5_page_drive_app_car.html\n
gadget_erp5_page_drive_app_car.js\n
drive_app_landing_page.html\n
gadget_officejs_drive_app_router.html\n
gadget_officejs_jio_drive_record_view.html\n
gadget_officejs_jio_drive_record_view.js\n
\n
#setting\n
gadget_officejs_setting.js\n
gadget_officejs_setting.html\n
NETWORK:\n
*</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Drive App Gadget OfficeJS AppCache</string> </value>
<value> <string>jio_precachestorage.js</string> </value>
</item>
<item>
<key> <string>url_string</string> </key>
......@@ -322,7 +197,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1503461993.92</float>
<float>1586165638.67</float>
<string>UTC</string>
</tuple>
</state>
......@@ -371,7 +246,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>977.38881.34981.23125</string> </value>
<value> <string>983.46175.933.7662</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -389,7 +264,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1582043052.59</float>
<float>1588765387.52</float>
<string>UTC</string>
</tuple>
</state>
......@@ -450,7 +325,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1503459831.13</float>
<float>1586165299.65</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -17,6 +17,7 @@
<script src="zipfilestorage-with-jszip.js"></script>
<script src="jio_filesystemstorage.js"></script>
<script src="jio_appcachestorage.js"></script>
<script src="jio_precachestorage.js"></script>
</head>
......
......@@ -6,18 +6,23 @@
var origin_url = (window.location.origin + window.location.pathname)
.replace("officejs_export/", ""),
precache_manifest = "WebSection_getPrecacheManifest",
//TODO get rid of this old HARDCODED app dict and get everything from config
application_dict = {
"Text Editor": {
"url": "officejs_text_editor/",
"cache": "gadget_officejs_text_editor.appcache"
"storage_type": "precache",
"cache": precache_manifest
},
"Smart Assistant": {
"url": "officejs_smart_assistant/",
"cache": "gadget_smart_assistant.appcache"
"storage_type": "precache",
"cache": precache_manifest
},
"Media Player": {
"url": "officejs_media_player/",
"cache": "gadget_officejs_media_player.appcache"
"storage_type": "precache",
"cache": precache_manifest
},
"Notebook": {
"url": "officejs_notebook/",
......@@ -25,11 +30,13 @@
},
"Illustration Editor": {
"url": "officejs_svg_editor/",
"cache": "gadget_officejs_illustration.appcache"
"storage_type": "precache",
"cache": precache_manifest
},
"PDF Viewer": {
"url": "officejs_pdf_viewer/",
"cache": "gadget_officejs_pdf_viewer.appcache"
"storage_type": "precache",
"cache": precache_manifest
},
"Cribjs": {
"url": "officejs_cribjs/",
......@@ -37,31 +44,38 @@
},
"Bookmark Manager": {
"url": "officejs_bookmark_manager/",
"cache" : "gadget_officejs_bookmark_manager.appcache"
"storage_type": "precache",
"cache": precache_manifest
},
"Onlyoffice Text": {
"url": "ooffice_text/",
"cache": "gadget_ooffice_text.appcache"
"storage_type": "precache",
"cache": precache_manifest
},
"Onlyoffice Spreadsheet": {
"url": "ooffice_spreadsheet/",
"cache": "gadget_ooffice_spreadsheet.appcache"
"storage_type": "precache",
"cache": precache_manifest
},
"Onlyoffice Presentation": {
"url": "ooffice_presentation/",
"cache": "gadget_ooffice_presentation.appcache"
"storage_type": "precache",
"cache": precache_manifest
},
"Web Table Editor": {
"url": "officejs_web_table_editor/",
"cache": "gadget_officejs_web_table.appcache"
"storage_type": "precache",
"cache": precache_manifest
},
"Image Editor": {
"url": "officejs_image_editor/",
"cache": "gadget_officejs_image_editor.appcache"
"storage_type": "precache",
"cache": precache_manifest
},
"Awesome Free Software Publisher List": {
"url": "afs/",
"cache": "gadget_erp5_afs.appcache",
"storage_type": "precache",
"cache": precache_manifest,
"no_installer": true
},
"Jabber Client": {
......@@ -99,7 +113,8 @@
},
"Drive App": {
"url": "officejs_drive_app/",
"cache": "gadget_officejs_drive_app.appcache"
"storage_type": "precache",
"cache": precache_manifest
},
"Travel Expense": {
"url": "officejs_hr/",
......@@ -108,7 +123,8 @@
},
"Javascript editor (CodeMirror)": {
"url": "officejs_codemirror/",
"cache": "gadget_officejs_codemirror.appcache"
"storage_type": "precache",
"cache": precache_manifest
}
};
......@@ -125,7 +141,8 @@
app = application_dict[form_result.web_site];
zip_name = form_result.filename;
return gadget.fillZip(app.cache, origin_url + app.url, app.no_installer)
return gadget.fillZip(app.storage_type, app.cache, origin_url + app.url,
app.no_installer)
.push(function (zip_file) {
var element = gadget.element,
a = document.createElement("a"),
......@@ -146,7 +163,8 @@
.ready(function (g) {
g.props = {};
})
.declareMethod("fillZip", function (cache_file, site_url, no_installer) {
.declareMethod("fillZip", function (storage_type, cache_file, site_url,
no_installer) {
var file_storage = jIO.createJIO({
type: "replicate",
conflict_handling: 2,
......@@ -160,7 +178,8 @@
type: "filesystem",
document: site_url,
sub_storage: {
type: "appcache",
//keep appcache as default for backward compatibility
type: storage_type || "appcache",
take_installer: no_installer === undefined,
manifest: cache_file,
origin_url: site_url,
......
......@@ -413,7 +413,7 @@
</item>
<item>
<key> <string>configuration_cache_file</string> </key>
<value> <string>gadget_officejs_pdf_viewer.appcache</string> </value>
<value> <string>WebSection_getPrecacheManifest</string> </value>
</item>
<item>
<key> <string>configuration_content_security_policy</string> </key>
......@@ -459,7 +459,7 @@
</item>
<item>
<key> <string>configuration_manifest_url</string> </key>
<value> <string>gadget_officejs.appcache</string> </value>
<value> <string></string> </value>
</item>
<item>
<key> <string>configuration_panel_gadget_url</string> </key>
......@@ -646,61 +646,65 @@
</record>
<record id="9" aka="AAAAAAAAAAk=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>973.33482.4166.8669</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1549644511.76</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>979.3226.30420.13465</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1587472029.55</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment