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.
This commit is contained in:
Benedict Aas 2017-07-04 18:11:44 +01:00 committed by Juan Cruz Viotti
parent f1ddf07a45
commit b18fa1f13f

View File

@ -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;