Path: blob/trunk/third_party/closure/goog/labs/html/attribute_rewriter.js
2868 views
// Copyright 2014 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.131415goog.provide('goog.labs.html.AttributeRewriter');16goog.provide('goog.labs.html.AttributeValue');17goog.provide('goog.labs.html.attributeRewriterPresubmitWorkaround');181920/**21* The type of an attribute value.22* <p>23* Many HTML attributes contain structured data like URLs, CSS, or even entire24* HTML documents, so the type is a union of several variants.25*26* @typedef {(string |27* goog.html.SafeHtml | goog.html.SafeStyle | goog.html.SafeUrl)}28*/29goog.labs.html.AttributeValue;303132/**33* A function that takes an attribute value, and returns a safe value.34* <p>35* Since rewriters can be chained, a rewriter must be able to accept the output36* of another rewriter, instead of just a string though a rewriter that coerces37* its input to a string before checking its safety will fail safe.38* <p>39* The meaning of the result is:40* <table>41* <tr><td>{@code null}</td>42* <td>Unsafe. The attribute should not be output.</tr>43* <tr><td>a string</td>44* <td>The plain text (not HTML-entity encoded) of a safe attribute45* value.</td>46* <tr><td>a {@link goog.html.SafeHtml}</td>47* <td>A fragment that is safe to be included as embedded HTML as in48* {@code <iframe srchtml="...">}</td></tr>49* <tr><td>a {@link goog.html.SafeUrl}</td>50* <td>A URL that does not need to be further checked against the URL51* white-list.</td></tr>52* <tr><td>a {@link goog.html.SafeStyle}</td>53* <td>A safe value for a <code>style="..."</code> attribute.</td></tr>54* </table>55* <p>56* Implementations are responsible for making sure that "safe" complies with57* the contract established by the safe string types in {@link goog.html}.58* </p>59*60* @typedef {function(goog.labs.html.AttributeValue) :61* goog.labs.html.AttributeValue}62*/63goog.labs.html.AttributeRewriter;646566/**67* g4 presubmit complains about requires of this file because its clients68* don't use any symbols from it outside JSCompiler comment annotations.69* genjsdeps.sh doesn't generate the right dependency graph unless this70* file is required.71* Clients can mention this noop.72*/73goog.labs.html.attributeRewriterPresubmitWorkaround = function() {};747576