Skip to content

Commit

Permalink
Make disableCSSInjection a global again
Browse files Browse the repository at this point in the history
  • Loading branch information
davidswinegar committed Jan 21, 2020
1 parent 4863ed3 commit 1c297ab
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 23 deletions.
4 changes: 2 additions & 2 deletions samples/advanced/content-security-policy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var utils = Samples.utils;

utils.srand(110);
// CSP: disable automatic style injection
Chart.platform.disableCSSInjection = true;

function generateData() {
var DATA_COUNT = 16;
Expand Down Expand Up @@ -46,8 +48,6 @@ window.addEventListener('load', function() {
}
}
},
// CSP: disable automatic style injection
disableCSSInjection: true
}
});
});
10 changes: 5 additions & 5 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import defaults from './core.defaults';
import helpers from '../helpers/index';
import Interaction from './core.interaction';
import layouts from './core.layouts';
import {BasicPlatform, DomPlatform} from '../platforms/platforms';
import {BasicPlatform, DomPlatform} from '../platform/platforms';
import plugins from './core.plugins';
import scaleService from '../core/core.scaleService';

Expand Down Expand Up @@ -253,13 +253,13 @@ class Chart {
const me = this;

if (config.platform) {
me.platform = new config.platform(config);
me.platform = new config.platform();
} else if (!isDomSupported()) {
me.platform = new BasicPlatform(config);
me.platform = new BasicPlatform();
} else if (window.OffscreenCanvas && canvas instanceof window.OffscreenCanvas) {
me.platform = new BasicPlatform(config);
me.platform = new BasicPlatform();
} else {
me.platform = new DomPlatform(config);
me.platform = new DomPlatform();
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import Element from './core/core.element';
import elements from './elements';
import Interaction from './core/core.interaction';
import layouts from './core/core.layouts';
import platforms from './platforms/platforms';
import platforms from './platform/platforms';
import platform from './platform/platform';
import pluginsCore from './core/core.plugins';
import Scale from './core/core.scale';
import scaleService from './core/core.scaleService';
Expand All @@ -34,6 +35,7 @@ Chart.elements = elements;
Chart.Interaction = Interaction;
Chart.layouts = layouts;
Chart.platforms = platforms;
Chart.platform = platform;
Chart.plugins = pluginsCore;
Chart.Scale = Scale;
Chart.scaleService = scaleService;
Expand Down
4 changes: 1 addition & 3 deletions src/platforms/platform.js → src/platform/platform.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
/**
* Abstract class that allows abstracting platform dependencies away from the chart.
*/
export default class Platform {
export default class BasePlatform {
/**
* @constructor
* The Platform constructor has no required parameters, but chart options are passed in as
* the first and only parameter to all Platform constructors.
*/
constructor() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

'use strict';

import Platform from './platform';
import BasePlatform from './platform.base';

/**
* Platform class for charts without access to the DOM or to many element properties
* This platform is used by default for any chart passed an OffscreenCanvas.
* @extends Platform
* @extends BasePlatform
*/
export default class BasicPlatform extends Platform {
export default class BasicPlatform extends BasePlatform {
acquireContext(item) {
// To prevent canvas fingerprinting, some add-ons undefine the getContext
// method, for example: https://github.com/kkapsner/CanvasBlocker
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions src/platforms/platform.dom.js → src/platform/platform.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import helpers from '../helpers';
import stylesheet from './platform.dom.css';
import Platform from './platform';
import BasePlatform from './platform.base';
import platform from './platform';

var EXPANDO_KEY = '$chartjs';
var CSS_PREFIX = 'chartjs-';
Expand Down Expand Up @@ -315,14 +316,13 @@ function injectCSS(rootNode, css) {

/**
* Platform class for charts that can access the DOM and global window/document properties
* @extends Platform
* @extends BasePlatform
*/
export default class DomPlatform extends Platform {
export default class DomPlatform extends BasePlatform {
/**
* @constructor
* @param {object} options - The chart options
*/
constructor(options) {
constructor() {
super();

/**
Expand All @@ -332,7 +332,7 @@ export default class DomPlatform extends Platform {
* to be manually imported to make this library compatible with any CSP.
* See https://github.com/chartjs/Chart.js/issues/5208
*/
this.disableCSSInjection = options.disableCSSInjection;
this.disableCSSInjection = platform.disableCSSInjection;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/platform/platform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

export default {disableCSSInjection: false};
6 changes: 3 additions & 3 deletions src/platforms/platforms.js → src/platform/platforms.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

import Platform from './platform';
import BasePlatform from './platform.base';
import BasicPlatform from './platform.basic';
import DomPlatform from './platform.dom';

export {BasicPlatform, DomPlatform, Platform};
export {BasicPlatform, DomPlatform, BasePlatform};

/**
* @namespace Chart.platforms
* @see https://chartjs.gitbooks.io/proposals/content/Platform.html
*/
export default {BasicPlatform, DomPlatform, Platform};
export default {BasicPlatform, DomPlatform, BasePlatform};

0 comments on commit 1c297ab

Please sign in to comment.