Path: blob/trunk/third_party/closure/goog/html/silverlight.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.131415/**16* @fileoverview SafeHtml factory methods for creating object tags for17* loading Silverlight files.18*/1920goog.provide('goog.html.silverlight');2122goog.require('goog.html.SafeHtml');23goog.require('goog.html.TrustedResourceUrl');24goog.require('goog.html.flash');25goog.require('goog.string.Const');262728/**29* Attributes and param tag name attributes not allowed to be overriden30* when calling createObjectForSilverlight().31*32* While values that should be specified as params are probably not33* recognized as attributes, we block them anyway just to be sure.34* @const {!Array<string>}35* @private36*/37goog.html.silverlight.FORBIDDEN_ATTRS_AND_PARAMS_ON_SILVERLIGHT_ = [38'data', // Always set to a fixed value.39'source', // Specifies the URL for the Silverlight file.40'type', // Always set to a fixed value.41'typemustmatch' // Always set to a fixed value.42];434445/**46* Creates a SafeHtml representing an object tag, for loading Silverlight files.47*48* The following attributes are set to these fixed values:49* - data: data:application/x-silverlight-2,50* - type: application/x-silverlight-251* - typemustmatch: "" (the empty string, meaning true for a boolean attribute)52*53* @param {!goog.html.TrustedResourceUrl} source The value of the source param.54* @param {?Object<string, string>=} opt_params Mapping used to generate child55* param tags. Each tag has a name and value attribute, as defined in56* mapping. Only names consisting of [a-zA-Z0-9-] are allowed. Value of57* null or undefined causes the param tag to be omitted.58* @param {?Object<string, ?goog.html.SafeHtml.AttributeValue>=} opt_attributes59* Mapping from other attribute names to their values. Only attribute names60* consisting of [a-zA-Z0-9-] are allowed. Value of null or undefined causes61* the attribute to be omitted.62* @return {!goog.html.SafeHtml} The SafeHtml content with the object tag.63* @throws {Error} If invalid attribute or param name, or attribute or param64* value is provided. Also if opt_attributes or opt_params contains any of65* the attributes set to fixed values, documented above, or contains source.66*67*/68goog.html.silverlight.createObject = function(69source, opt_params, opt_attributes) {70goog.html.flash.verifyKeysNotInMaps(71goog.html.silverlight.FORBIDDEN_ATTRS_AND_PARAMS_ON_SILVERLIGHT_,72opt_attributes, opt_params);7374// We don't set default for Silverlight's EnableHtmlAccess and75// AllowHtmlPopupwindow because their default changes depending on whether76// a file loaded from the same domain.77var paramTags = goog.html.flash.combineParams({'source': source}, opt_params);78var fixedAttributes = {79'data': goog.html.TrustedResourceUrl.fromConstant(80goog.string.Const.from('data:application/x-silverlight-2,')),81'type': 'application/x-silverlight-2',82'typemustmatch': ''83};84var attributes =85goog.html.SafeHtml.combineAttributes(fixedAttributes, {}, opt_attributes);8687return goog.html.SafeHtml.createSafeHtmlTagSecurityPrivateDoNotAccessOrElse(88'object', attributes, paramTags);89};909192