From b18fa1f13f17dbe1c9f595d2fc97b689d3179a17 Mon Sep 17 00:00:00 2001 From: Benedict Aas Date: Tue, 4 Jul 2017 18:11:44 +0100 Subject: [PATCH] feat(GUI): add webview api version parameter (#1558) We add the API version sent to the banner via a GET search parameter, allowing for more intricate control over what data needs or can be sent. --- lib/gui/components/safe-webview.js | 43 +++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/lib/gui/components/safe-webview.js b/lib/gui/components/safe-webview.js index ad5f9d41..c6c95d8b 100644 --- a/lib/gui/components/safe-webview.js +++ b/lib/gui/components/safe-webview.js @@ -29,14 +29,6 @@ const robot = require('../../shared/robot'); const MODULE_NAME = 'Etcher.Components.SafeWebview'; const angularSafeWebview = angular.module(MODULE_NAME, []); -/** - * @summary GET parameter sent to the initial webview source URL - * @constant - * @private - * @type {String} - */ -const VERSION_PARAM = 'etcher-version'; - /** * @summary Electron session identifier * @constant @@ -45,6 +37,36 @@ const VERSION_PARAM = 'etcher-version'; */ const ELECTRON_SESSION = 'persist:success-banner'; +/** + * @summary Etcher version search-parameter key + * @constant + * @private + * @type {String} + */ +const ETCHER_VERSION_PARAM = 'etcher-version'; + +/** + * @summary API version search-parameter key + * @constant + * @private + * @type {String} + */ +const API_VERSION_PARAM = 'api-version'; + +/** + * @summary Webview API version + * @constant + * @private + * @type {String} + * + * @description + * Changing this number represents a departure from an older API and as such + * should only be changed when truly necessary as it introduces breaking changes. + * This version number is exposed to the banner such that it can determine what + * features are safe to utilize. + */ +const API_VERSION = 1; + /** * @summary Webviews that hide/show depending on the HTTP status returned * @type {Object} @@ -67,8 +89,9 @@ class SafeWebview extends react.PureComponent { const url = new URL(props.src); - // We set the version GET parameter here. - url.searchParams.set(VERSION_PARAM, packageJSON.version); + // We set the version GET parameters here. + url.searchParams.set(ETCHER_VERSION_PARAM, packageJSON.version); + url.searchParams.set(API_VERSION_PARAM, API_VERSION); this.entryHref = url.href;