Skip to content

Commit

Permalink
Use Trusted Types externs.
Browse files Browse the repository at this point in the history
I've ported https://cs.chromium.org/lang:idl%20%5Cb(HTML%7CScript%7CScriptURL%7CURL)String%5Cb here.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=231185103
  • Loading branch information
vrana authored and tjgq committed Jan 29, 2019
1 parent 4028470 commit 0aee97d
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 17 deletions.
6 changes: 3 additions & 3 deletions externs/browser/gecko_dom.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -550,14 +550,14 @@ Document.prototype.queryCommandValue;


/** /**
* @see https://developer.mozilla.org/en/DOM/document.write * @see https://developer.mozilla.org/en/DOM/document.write
* @param {string} text * @param {!TrustedHTML|string} text
* @return {undefined} * @return {undefined}
*/ */
Document.prototype.write = function(text) {}; Document.prototype.write = function(text) {};


/** /**
* @see https://developer.mozilla.org/en/DOM/document.writeln * @see https://developer.mozilla.org/en/DOM/document.writeln
* @param {string} text * @param {!TrustedHTML|string} text
* @return {undefined} * @return {undefined}
*/ */
Document.prototype.writeln = function(text) {}; Document.prototype.writeln = function(text) {};
Expand All @@ -577,7 +577,7 @@ Document.prototype.getBoxObjectFor = function(element) {};
// http://lxr.mozilla.org/mozilla1.8/source/dom/public/idl/range/nsIDOMNSRange.idl // http://lxr.mozilla.org/mozilla1.8/source/dom/public/idl/range/nsIDOMNSRange.idl


/** /**
* @param {string} tag * @param {!TrustedHTML|string} tag
* @return {DocumentFragment} * @return {DocumentFragment}
*/ */
Range.prototype.createContextualFragment; Range.prototype.createContextualFragment;
Expand Down
2 changes: 1 addition & 1 deletion externs/browser/gecko_xml.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function DOMParser() {}
* var parser = new DOMParser(); * var parser = new DOMParser();
* var doc = parser.parseFromString(aStr, "text/xml"); * var doc = parser.parseFromString(aStr, "text/xml");
* *
* @param {string} src The UTF16 string to be parsed. * @param {!TrustedHTML|string} src The UTF16 string to be parsed.
* @param {string} type The content type of the string. * @param {string} type The content type of the string.
* @return {Document} * @return {Document}
*/ */
Expand Down
15 changes: 10 additions & 5 deletions externs/browser/html5.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1272,14 +1272,14 @@ Window.prototype.applicationCache;


/** /**
* @see https://developer.mozilla.org/En/DOM/Worker/Functions_available_to_workers * @see https://developer.mozilla.org/En/DOM/Worker/Functions_available_to_workers
* @param {...string} var_args * @param {...!TrustedScriptURL|string} var_args
* @return {undefined} * @return {undefined}
*/ */
Window.prototype.importScripts = function(var_args) {}; Window.prototype.importScripts = function(var_args) {};


/** /**
* @see https://developer.mozilla.org/En/DOM/Worker/Functions_available_to_workers * @see https://developer.mozilla.org/En/DOM/Worker/Functions_available_to_workers
* @param {...string} var_args * @param {...!TrustedScriptURL|string} var_args
* @return {undefined} * @return {undefined}
*/ */
function importScripts(var_args) {} function importScripts(var_args) {}
Expand Down Expand Up @@ -1727,6 +1727,7 @@ HTMLAreaElement.prototype.ping;


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/html-markup/iframe.html#iframe.attrs.srcdoc * @see http://www.w3.org/TR/html-markup/iframe.html#iframe.attrs.srcdoc
*/ */
HTMLIFrameElement.prototype.srcdoc; HTMLIFrameElement.prototype.srcdoc;
Expand Down Expand Up @@ -1843,7 +1844,7 @@ HTMLMediaElement.HAVE_ENOUGH_DATA; // = 4
/** @type {MediaError} */ /** @type {MediaError} */
HTMLMediaElement.prototype.error; HTMLMediaElement.prototype.error;


/** @type {string} */ /** @type {string} @implicitCast */
HTMLMediaElement.prototype.src; HTMLMediaElement.prototype.src;


/** @type {string} */ /** @type {string} */
Expand Down Expand Up @@ -3458,6 +3459,7 @@ HTMLButtonElement.prototype.setCustomValidity = function(message) {};


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/html5/forms.html#attr-fs-formaction * @see http://www.w3.org/TR/html5/forms.html#attr-fs-formaction
*/ */
HTMLButtonElement.prototype.formAction; HTMLButtonElement.prototype.formAction;
Expand Down Expand Up @@ -3488,6 +3490,7 @@ HTMLInputElement.prototype.formNoValidate;


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/html5/forms.html#attr-fs-formaction * @see http://www.w3.org/TR/html5/forms.html#attr-fs-formaction
*/ */
HTMLInputElement.prototype.formAction; HTMLInputElement.prototype.formAction;
Expand Down Expand Up @@ -3639,6 +3642,7 @@ HTMLEmbedElement.prototype.height;


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/html5/the-embed-element.html#dom-embed-src * @see http://www.w3.org/TR/html5/the-embed-element.html#dom-embed-src
*/ */
HTMLEmbedElement.prototype.src; HTMLEmbedElement.prototype.src;
Expand Down Expand Up @@ -4013,6 +4017,7 @@ ShadowRoot.prototype.olderShadowRoot;


/** /**
* @type {string} * @type {string}
* @implicitCast
*/ */
ShadowRoot.prototype.innerHTML; ShadowRoot.prototype.innerHTML;


Expand Down Expand Up @@ -4134,7 +4139,7 @@ HTMLSourceElement.prototype.media;
/** @type {string} */ /** @type {string} */
HTMLSourceElement.prototype.sizes; HTMLSourceElement.prototype.sizes;


/** @type {string} */ /** @type {string} @implicitCast */
HTMLSourceElement.prototype.src; HTMLSourceElement.prototype.src;


/** @type {string} */ /** @type {string} */
Expand Down Expand Up @@ -4528,7 +4533,7 @@ function HTMLTrackElement() {}
HTMLTrackElement.prototype.kind; HTMLTrackElement.prototype.kind;




/** @type {string} */ /** @type {string} @implicitCast */
HTMLTrackElement.prototype.src; HTMLTrackElement.prototype.src;




Expand Down
8 changes: 5 additions & 3 deletions externs/browser/ie_dom.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Node.prototype.document;
* Inserts the given HTML text into the element at the location. * Inserts the given HTML text into the element at the location.
* @param {string} sWhere Where to insert the HTML text, one of 'beforeBegin', * @param {string} sWhere Where to insert the HTML text, one of 'beforeBegin',
* 'afterBegin', 'beforeEnd', 'afterEnd'. * 'afterBegin', 'beforeEnd', 'afterEnd'.
* @param {string} sText HTML text to insert. * @param {!TrustedHTML|string} sText HTML text to insert.
* @see http://msdn.microsoft.com/en-us/library/ms536452(VS.85).aspx * @see http://msdn.microsoft.com/en-us/library/ms536452(VS.85).aspx
* @return {undefined} * @return {undefined}
*/ */
Expand Down Expand Up @@ -1123,6 +1123,7 @@ Element.prototype.onselectstart;


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://msdn.microsoft.com/en-us/library/aa752326(VS.85).aspx * @see http://msdn.microsoft.com/en-us/library/aa752326(VS.85).aspx
*/ */
Element.prototype.outerHTML; Element.prototype.outerHTML;
Expand Down Expand Up @@ -1260,6 +1261,7 @@ Location.prototype.hostname;


/** /**
* @see http://msdn.microsoft.com/en-us/library/ms533867(VS.85).aspx * @see http://msdn.microsoft.com/en-us/library/ms533867(VS.85).aspx
* @implicitCast
* @type {string} * @type {string}
*/ */
Location.prototype.href; Location.prototype.href;
Expand Down Expand Up @@ -1296,7 +1298,7 @@ Location.prototype.search;


/** /**
* @see http://msdn.microsoft.com/en-us/library/ms536342(VS.85).aspx * @see http://msdn.microsoft.com/en-us/library/ms536342(VS.85).aspx
* @param {string} url * @param {!TrustedURL|string} url
* @return {undefined} * @return {undefined}
*/ */
Location.prototype.assign = function(url) {}; Location.prototype.assign = function(url) {};
Expand All @@ -1310,7 +1312,7 @@ Location.prototype.assign = function(url) {};
Location.prototype.reload = function(opt_forceReload) {}; Location.prototype.reload = function(opt_forceReload) {};


/** /**
* @param {string} url * @param {!TrustedURL|string} url
* @see http://msdn.microsoft.com/en-us/library/ms536712(VS.85).aspx * @see http://msdn.microsoft.com/en-us/library/ms536712(VS.85).aspx
* @return {undefined} * @return {undefined}
*/ */
Expand Down
16 changes: 14 additions & 2 deletions externs/browser/w3c_dom2.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -258,15 +258,15 @@ HTMLDocument.prototype.open = function(opt_mimeType, opt_replace) {};
HTMLDocument.prototype.close = function() {}; HTMLDocument.prototype.close = function() {};


/** /**
* @param {string} text * @param {!TrustedHTML|string} text
* @return {undefined} * @return {undefined}
* @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-75233634 * @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-75233634
* @override * @override
*/ */
HTMLDocument.prototype.write = function(text) {}; HTMLDocument.prototype.write = function(text) {};


/** /**
* @param {string} text * @param {!TrustedHTML|string} text
* @return {undefined} * @return {undefined}
* @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-35318390 * @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-35318390
* @override * @override
Expand Down Expand Up @@ -518,6 +518,7 @@ HTMLLinkElement.prototype.charset;


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-33532588 * @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-33532588
*/ */
HTMLLinkElement.prototype.href; HTMLLinkElement.prototype.href;
Expand Down Expand Up @@ -614,6 +615,7 @@ function HTMLBaseElement() {}


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-65382887 * @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-65382887
*/ */
HTMLBaseElement.prototype.href; HTMLBaseElement.prototype.href;
Expand Down Expand Up @@ -768,6 +770,7 @@ HTMLFormElement.prototype.acceptCharset;


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-74049184 * @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-74049184
*/ */
HTMLFormElement.prototype.action; HTMLFormElement.prototype.action;
Expand Down Expand Up @@ -1062,6 +1065,7 @@ HTMLInputElement.prototype.size;


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-97320704 * @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-97320704
*/ */
HTMLInputElement.prototype.src; HTMLInputElement.prototype.src;
Expand Down Expand Up @@ -1639,6 +1643,7 @@ HTMLAnchorElement.prototype.coords;


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-88517319 * @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-88517319
*/ */
HTMLAnchorElement.prototype.href; HTMLAnchorElement.prototype.href;
Expand Down Expand Up @@ -1824,6 +1829,7 @@ HTMLObjectElement.prototype.code;


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-25709136 * @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-25709136
*/ */
HTMLObjectElement.prototype.codeBase; HTMLObjectElement.prototype.codeBase;
Expand All @@ -1842,6 +1848,7 @@ HTMLObjectElement.prototype.contentDocument;


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-81766986 * @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-81766986
*/ */
HTMLObjectElement.prototype.data; HTMLObjectElement.prototype.data;
Expand Down Expand Up @@ -2066,6 +2073,7 @@ HTMLAreaElement.prototype.coords;


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-34672936 * @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-34672936
*/ */
HTMLAreaElement.prototype.href; HTMLAreaElement.prototype.href;
Expand Down Expand Up @@ -2132,12 +2140,14 @@ HTMLScriptElement.prototype.onreadystatechange;


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-75147231 * @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-75147231
*/ */
HTMLScriptElement.prototype.src; HTMLScriptElement.prototype.src;


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-46872999 * @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-46872999
*/ */
HTMLScriptElement.prototype.text; HTMLScriptElement.prototype.text;
Expand Down Expand Up @@ -2642,6 +2652,7 @@ HTMLFrameElement.prototype.scrolling;


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-78799535 * @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-78799535
*/ */
HTMLFrameElement.prototype.src; HTMLFrameElement.prototype.src;
Expand Down Expand Up @@ -2710,6 +2721,7 @@ HTMLIFrameElement.prototype.scrolling;


/** /**
* @type {string} * @type {string}
* @implicitCast
* @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-43933957 * @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-43933957
*/ */
HTMLIFrameElement.prototype.src; HTMLIFrameElement.prototype.src;
Expand Down
92 changes: 92 additions & 0 deletions externs/browser/w3c_trusted_types.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright 2018 The Closure Compiler Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview Definitions for W3C's Trusted Types specification.
* @see https://github.com/WICG/trusted-types
* @externs
*/


/** @constructor */
function TrustedHTML() {}

/** @constructor */
function TrustedScript() {}

/** @constructor */
function TrustedScriptURL() {}

/** @constructor */
function TrustedURL() {}


/** @constructor */
function TrustedTypePolicy() {}

/**
* @param {string} s
* @return {!TrustedHTML}
*/
TrustedTypePolicy.prototype.createHTML = function(s) {};

/**
* @param {string} s
* @return {!TrustedScript}
*/
TrustedTypePolicy.prototype.createScript = function(s) {};

/**
* @param {string} s
* @return {!TrustedScriptURL}
*/
TrustedTypePolicy.prototype.createScriptURL = function(s) {};

/**
* @param {string} s
* @return {!TrustedURL}
*/
TrustedTypePolicy.prototype.createURL = function(s) {};


/** @constructor */
function TrustedTypePolicyFactory() {}

/**
* @param {string} name
* @param {{
* createHTML: function(string): string,
* createScript: function(string): string,
* createScriptURL: function(string): string,
* createURL: function(string): string}} policy
* @param {boolean=} opt_expose
* @return {!TrustedTypePolicy}
*/
TrustedTypePolicyFactory.prototype.createPolicy = function(
name, policy, opt_expose) {};

/**
* @param {string} name
* @return {!TrustedTypePolicy}
*/
TrustedTypePolicyFactory.prototype.getExposedPolicy = function(name) {};

/** @return {!Array<string>} */
TrustedTypePolicyFactory.prototype.getPolicyNames = function() {};


/** @type {!TrustedTypePolicyFactory} */
var TrustedTypes;
4 changes: 2 additions & 2 deletions externs/browser/window.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function prompt(message, opt_value) {}
function setImmediate(callback, var_args) {} function setImmediate(callback, var_args) {}


/** /**
* @param {Function|string} callback * @param {Function|!TrustedScript|string} callback
* @param {number=} opt_delay * @param {number=} opt_delay
* @param {...?} var_args * @param {...?} var_args
* @return {number} * @return {number}
Expand All @@ -199,7 +199,7 @@ function setImmediate(callback, var_args) {}
function setInterval(callback, opt_delay, var_args) {} function setInterval(callback, opt_delay, var_args) {}


/** /**
* @param {Function|string} callback * @param {Function|!TrustedScript|string} callback
* @param {number=} opt_delay * @param {number=} opt_delay
* @param {...*} var_args * @param {...*} var_args
* @return {number} * @return {number}
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/resources.json

Large diffs are not rendered by default.

0 comments on commit 0aee97d

Please sign in to comment.