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
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<script src="${latest_version}/rsvp.js"></script> <script src="${latest_version}/rsvp.js"></script>
<script src="${latest_version}/renderjs.js"></script> <script src="${latest_version}/renderjs.js"></script>
<script src="${latest_version}/jiodev.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> <script src="gadget_officejs_bootloader.js"></script>
</head> </head>
......
...@@ -36,7 +36,7 @@ var repair = false; ...@@ -36,7 +36,7 @@ var repair = false;
} }
}, },
remote_sub_storage: { remote_sub_storage: {
type: "appcache", type: "precache",
manifest: gadget.props.cache_file, manifest: gadget.props.cache_file,
version: gadget.props.version_url, version: gadget.props.version_url,
take_installer: true take_installer: true
...@@ -176,4 +176,4 @@ var repair = false; ...@@ -176,4 +176,4 @@ var repair = false;
return; return;
}); });
}(window, document, RSVP, rJS, jIO, navigator, URL)); }(window, document, RSVP, rJS, jIO, navigator, URL));
\ No newline at end of file
/*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 @@ ...@@ -2,7 +2,7 @@
<ZopeData> <ZopeData>
<record id="1" aka="AAAAAAAAAAE="> <record id="1" aka="AAAAAAAAAAE=">
<pickle> <pickle>
<global name="Web Manifest" module="erp5.portal_type"/> <global name="Web Script" module="erp5.portal_type"/>
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
...@@ -64,9 +64,7 @@ ...@@ -64,9 +64,7 @@
<item> <item>
<key> <string>categories</string> </key> <key> <string>categories</string> </key>
<value> <value>
<tuple> <tuple/>
<string>contributor/person_module/1</string>
</tuple>
</value> </value>
</item> </item>
<item> <item>
...@@ -75,13 +73,9 @@ ...@@ -75,13 +73,9 @@
<none/> <none/>
</value> </value>
</item> </item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/plain</string> </value>
</item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>gadget_officejs_drive_app.appcache</string> </value> <value> <string>jio_precachestorage.js</string> </value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
...@@ -91,7 +85,7 @@ ...@@ -91,7 +85,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <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>
<item> <item>
<key> <string>language</string> </key> <key> <string>language</string> </key>
...@@ -99,7 +93,7 @@ ...@@ -99,7 +93,7 @@
</item> </item>
<item> <item>
<key> <string>portal_type</string> </key> <key> <string>portal_type</string> </key>
<value> <string>Web Manifest</string> </value> <value> <string>Web Script</string> </value>
</item> </item>
<item> <item>
<key> <string>short_title</string> </key> <key> <string>short_title</string> </key>
...@@ -107,128 +101,9 @@ ...@@ -107,128 +101,9 @@
<none/> <none/>
</value> </value>
</item> </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> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>Drive App Gadget OfficeJS AppCache</string> </value> <value> <string>jio_precachestorage.js</string> </value>
</item> </item>
<item> <item>
<key> <string>url_string</string> </key> <key> <string>url_string</string> </key>
...@@ -322,7 +197,7 @@ NETWORK:\n ...@@ -322,7 +197,7 @@ NETWORK:\n
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1503461993.92</float> <float>1586165638.67</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
...@@ -371,7 +246,7 @@ NETWORK:\n ...@@ -371,7 +246,7 @@ NETWORK:\n
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>977.38881.34981.23125</string> </value> <value> <string>983.46175.933.7662</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -389,7 +264,7 @@ NETWORK:\n ...@@ -389,7 +264,7 @@ NETWORK:\n
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1582043052.59</float> <float>1588765387.52</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
...@@ -450,7 +325,7 @@ NETWORK:\n ...@@ -450,7 +325,7 @@ NETWORK:\n
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1503459831.13</float> <float>1586165299.65</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<script src="zipfilestorage-with-jszip.js"></script> <script src="zipfilestorage-with-jszip.js"></script>
<script src="jio_filesystemstorage.js"></script> <script src="jio_filesystemstorage.js"></script>
<script src="jio_appcachestorage.js"></script> <script src="jio_appcachestorage.js"></script>
<script src="jio_precachestorage.js"></script>
</head> </head>
......
...@@ -6,18 +6,23 @@ ...@@ -6,18 +6,23 @@
var origin_url = (window.location.origin + window.location.pathname) var origin_url = (window.location.origin + window.location.pathname)
.replace("officejs_export/", ""), .replace("officejs_export/", ""),
precache_manifest = "WebSection_getPrecacheManifest",
//TODO get rid of this old HARDCODED app dict and get everything from config
application_dict = { application_dict = {
"Text Editor": { "Text Editor": {
"url": "officejs_text_editor/", "url": "officejs_text_editor/",
"cache": "gadget_officejs_text_editor.appcache" "storage_type": "precache",
"cache": precache_manifest
}, },
"Smart Assistant": { "Smart Assistant": {
"url": "officejs_smart_assistant/", "url": "officejs_smart_assistant/",
"cache": "gadget_smart_assistant.appcache" "storage_type": "precache",
"cache": precache_manifest
}, },
"Media Player": { "Media Player": {
"url": "officejs_media_player/", "url": "officejs_media_player/",
"cache": "gadget_officejs_media_player.appcache" "storage_type": "precache",
"cache": precache_manifest
}, },
"Notebook": { "Notebook": {
"url": "officejs_notebook/", "url": "officejs_notebook/",
...@@ -25,11 +30,13 @@ ...@@ -25,11 +30,13 @@
}, },
"Illustration Editor": { "Illustration Editor": {
"url": "officejs_svg_editor/", "url": "officejs_svg_editor/",
"cache": "gadget_officejs_illustration.appcache" "storage_type": "precache",
"cache": precache_manifest
}, },
"PDF Viewer": { "PDF Viewer": {
"url": "officejs_pdf_viewer/", "url": "officejs_pdf_viewer/",
"cache": "gadget_officejs_pdf_viewer.appcache" "storage_type": "precache",
"cache": precache_manifest
}, },
"Cribjs": { "Cribjs": {
"url": "officejs_cribjs/", "url": "officejs_cribjs/",
...@@ -37,31 +44,38 @@ ...@@ -37,31 +44,38 @@
}, },
"Bookmark Manager": { "Bookmark Manager": {
"url": "officejs_bookmark_manager/", "url": "officejs_bookmark_manager/",
"cache" : "gadget_officejs_bookmark_manager.appcache" "storage_type": "precache",
"cache": precache_manifest
}, },
"Onlyoffice Text": { "Onlyoffice Text": {
"url": "ooffice_text/", "url": "ooffice_text/",
"cache": "gadget_ooffice_text.appcache" "storage_type": "precache",
"cache": precache_manifest
}, },
"Onlyoffice Spreadsheet": { "Onlyoffice Spreadsheet": {
"url": "ooffice_spreadsheet/", "url": "ooffice_spreadsheet/",
"cache": "gadget_ooffice_spreadsheet.appcache" "storage_type": "precache",
"cache": precache_manifest
}, },
"Onlyoffice Presentation": { "Onlyoffice Presentation": {
"url": "ooffice_presentation/", "url": "ooffice_presentation/",
"cache": "gadget_ooffice_presentation.appcache" "storage_type": "precache",
"cache": precache_manifest
}, },
"Web Table Editor": { "Web Table Editor": {
"url": "officejs_web_table_editor/", "url": "officejs_web_table_editor/",
"cache": "gadget_officejs_web_table.appcache" "storage_type": "precache",
"cache": precache_manifest
}, },
"Image Editor": { "Image Editor": {
"url": "officejs_image_editor/", "url": "officejs_image_editor/",
"cache": "gadget_officejs_image_editor.appcache" "storage_type": "precache",
"cache": precache_manifest
}, },
"Awesome Free Software Publisher List": { "Awesome Free Software Publisher List": {
"url": "afs/", "url": "afs/",
"cache": "gadget_erp5_afs.appcache", "storage_type": "precache",
"cache": precache_manifest,
"no_installer": true "no_installer": true
}, },
"Jabber Client": { "Jabber Client": {
...@@ -99,7 +113,8 @@ ...@@ -99,7 +113,8 @@
}, },
"Drive App": { "Drive App": {
"url": "officejs_drive_app/", "url": "officejs_drive_app/",
"cache": "gadget_officejs_drive_app.appcache" "storage_type": "precache",
"cache": precache_manifest
}, },
"Travel Expense": { "Travel Expense": {
"url": "officejs_hr/", "url": "officejs_hr/",
...@@ -108,7 +123,8 @@ ...@@ -108,7 +123,8 @@
}, },
"Javascript editor (CodeMirror)": { "Javascript editor (CodeMirror)": {
"url": "officejs_codemirror/", "url": "officejs_codemirror/",
"cache": "gadget_officejs_codemirror.appcache" "storage_type": "precache",
"cache": precache_manifest
} }
}; };
...@@ -125,7 +141,8 @@ ...@@ -125,7 +141,8 @@
app = application_dict[form_result.web_site]; app = application_dict[form_result.web_site];
zip_name = form_result.filename; 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) { .push(function (zip_file) {
var element = gadget.element, var element = gadget.element,
a = document.createElement("a"), a = document.createElement("a"),
...@@ -146,7 +163,8 @@ ...@@ -146,7 +163,8 @@
.ready(function (g) { .ready(function (g) {
g.props = {}; 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({ var file_storage = jIO.createJIO({
type: "replicate", type: "replicate",
conflict_handling: 2, conflict_handling: 2,
...@@ -160,7 +178,8 @@ ...@@ -160,7 +178,8 @@
type: "filesystem", type: "filesystem",
document: site_url, document: site_url,
sub_storage: { sub_storage: {
type: "appcache", //keep appcache as default for backward compatibility
type: storage_type || "appcache",
take_installer: no_installer === undefined, take_installer: no_installer === undefined,
manifest: cache_file, manifest: cache_file,
origin_url: site_url, origin_url: site_url,
......
...@@ -413,7 +413,7 @@ ...@@ -413,7 +413,7 @@
</item> </item>
<item> <item>
<key> <string>configuration_cache_file</string> </key> <key> <string>configuration_cache_file</string> </key>
<value> <string>gadget_officejs_pdf_viewer.appcache</string> </value> <value> <string>WebSection_getPrecacheManifest</string> </value>
</item> </item>
<item> <item>
<key> <string>configuration_content_security_policy</string> </key> <key> <string>configuration_content_security_policy</string> </key>
...@@ -459,7 +459,7 @@ ...@@ -459,7 +459,7 @@
</item> </item>
<item> <item>
<key> <string>configuration_manifest_url</string> </key> <key> <string>configuration_manifest_url</string> </key>
<value> <string>gadget_officejs.appcache</string> </value> <value> <string></string> </value>
</item> </item>
<item> <item>
<key> <string>configuration_panel_gadget_url</string> </key> <key> <string>configuration_panel_gadget_url</string> </key>
...@@ -646,61 +646,65 @@ ...@@ -646,61 +646,65 @@
</record> </record>
<record id="9" aka="AAAAAAAAAAk="> <record id="9" aka="AAAAAAAAAAk=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<list> <key> <string>_log</string> </key>
<dictionary> <value>
<item> <list>
<key> <string>action</string> </key> <dictionary>
<value> <string>edit</string> </value> <item>
</item> <key> <string>action</string> </key>
<item> <value> <string>edit</string> </value>
<key> <string>actor</string> </key> </item>
<value> <string>zope</string> </value> <item>
</item> <key> <string>actor</string> </key>
<item> <value> <string>zope</string> </value>
<key> <string>comment</string> </key> </item>
<value> <item>
<none/> <key> <string>comment</string> </key>
</value> <value>
</item> <none/>
<item> </value>
<key> <string>error_message</string> </key> </item>
<value> <string></string> </value> <item>
</item> <key> <string>error_message</string> </key>
<item> <value> <string></string> </value>
<key> <string>serial</string> </key> </item>
<value> <string>973.33482.4166.8669</string> </value> <item>
</item> <key> <string>serial</string> </key>
<item> <value> <string>979.3226.30420.13465</string> </value>
<key> <string>state</string> </key> </item>
<value> <string>current</string> </value> <item>
</item> <key> <string>state</string> </key>
<item> <value> <string>current</string> </value>
<key> <string>time</string> </key> </item>
<value> <item>
<object> <key> <string>time</string> </key>
<klass> <value>
<global name="DateTime" module="DateTime.DateTime"/> <object>
</klass> <klass>
<tuple> <global name="DateTime" module="DateTime.DateTime"/>
<none/> </klass>
</tuple> <tuple>
<state> <none/>
<tuple> </tuple>
<float>1549644511.76</float> <state>
<string>UTC</string> <tuple>
</tuple> <float>1587472029.55</float>
</state> <string>UTC</string>
</object> </tuple>
</value> </state>
</item> </object>
</dictionary> </value>
</list> </item>
</tuple> </dictionary>
</list>
</value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </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