silverlight.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2014 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview SafeHtml factory methods for creating object tags for
  16. * loading Silverlight files.
  17. */
  18. goog.provide('goog.html.silverlight');
  19. goog.require('goog.html.SafeHtml');
  20. goog.require('goog.html.TrustedResourceUrl');
  21. goog.require('goog.html.flash');
  22. goog.require('goog.string.Const');
  23. /**
  24. * Attributes and param tag name attributes not allowed to be overriden
  25. * when calling createObjectForSilverlight().
  26. *
  27. * While values that should be specified as params are probably not
  28. * recognized as attributes, we block them anyway just to be sure.
  29. * @const {!Array<string>}
  30. * @private
  31. */
  32. goog.html.silverlight.FORBIDDEN_ATTRS_AND_PARAMS_ON_SILVERLIGHT_ = [
  33. 'data', // Always set to a fixed value.
  34. 'source', // Specifies the URL for the Silverlight file.
  35. 'type', // Always set to a fixed value.
  36. 'typemustmatch' // Always set to a fixed value.
  37. ];
  38. /**
  39. * Creates a SafeHtml representing an object tag, for loading Silverlight files.
  40. *
  41. * The following attributes are set to these fixed values:
  42. * - data: data:application/x-silverlight-2,
  43. * - type: application/x-silverlight-2
  44. * - typemustmatch: "" (the empty string, meaning true for a boolean attribute)
  45. *
  46. * @param {!goog.html.TrustedResourceUrl} source The value of the source param.
  47. * @param {?Object<string, string>=} opt_params Mapping used to generate child
  48. * param tags. Each tag has a name and value attribute, as defined in
  49. * mapping. Only names consisting of [a-zA-Z0-9-] are allowed. Value of
  50. * null or undefined causes the param tag to be omitted.
  51. * @param {?Object<string, ?goog.html.SafeHtml.AttributeValue>=} opt_attributes
  52. * Mapping from other attribute names to their values. Only attribute names
  53. * consisting of [a-zA-Z0-9-] are allowed. Value of null or undefined causes
  54. * the attribute to be omitted.
  55. * @return {!goog.html.SafeHtml} The SafeHtml content with the object tag.
  56. * @throws {Error} If invalid attribute or param name, or attribute or param
  57. * value is provided. Also if opt_attributes or opt_params contains any of
  58. * the attributes set to fixed values, documented above, or contains source.
  59. *
  60. */
  61. goog.html.silverlight.createObject = function(
  62. source, opt_params, opt_attributes) {
  63. goog.html.flash.verifyKeysNotInMaps(
  64. goog.html.silverlight.FORBIDDEN_ATTRS_AND_PARAMS_ON_SILVERLIGHT_,
  65. opt_attributes, opt_params);
  66. // We don't set default for Silverlight's EnableHtmlAccess and
  67. // AllowHtmlPopupwindow because their default changes depending on whether
  68. // a file loaded from the same domain.
  69. var paramTags = goog.html.flash.combineParams({'source': source}, opt_params);
  70. var fixedAttributes = {
  71. 'data': goog.html.TrustedResourceUrl.fromConstant(
  72. goog.string.Const.from('data:application/x-silverlight-2,')),
  73. 'type': 'application/x-silverlight-2',
  74. 'typemustmatch': ''
  75. };
  76. var attributes =
  77. goog.html.SafeHtml.combineAttributes(fixedAttributes, {}, opt_attributes);
  78. return goog.html.SafeHtml.createSafeHtmlTagSecurityPrivateDoNotAccessOrElse(
  79. 'object', attributes, paramTags);
  80. };