sanitizeHtml.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*global define*/
  2. define([
  3. '../Core/defined',
  4. '../Core/RuntimeError',
  5. './createTaskProcessorWorker'
  6. ], function(
  7. defined,
  8. RuntimeError,
  9. createTaskProcessorWorker) {
  10. "use strict";
  11. var cajaScript = 'https://caja.appspot.com/html-css-sanitizer-minified.js';
  12. var html_sanitize;
  13. /**
  14. * A worker that loads the Google Caja HTML & CSS sanitizer and sanitizes the
  15. * provided HTML string.
  16. *
  17. * @exports sanitize
  18. *
  19. * @see TaskProcessor
  20. * @see {@link http://www.w3.org/TR/workers/|Web Workers}
  21. */
  22. var sanitizeHtml = function(html) {
  23. if (!defined(html_sanitize)) {
  24. /*global self,importScripts*/
  25. self.window = {};
  26. importScripts(cajaScript); // importScripts is synchronous
  27. html_sanitize = window.html_sanitize;
  28. if (!defined(html_sanitize)) {
  29. throw new RuntimeError('Unable to load Google Caja sanitizer script.');
  30. }
  31. }
  32. return html_sanitize(html);
  33. };
  34. return createTaskProcessorWorker(sanitizeHtml);
  35. });