/platform/external/webkit/WebCore/bindings/generic/BindingElement.h

https://github.com/aharish/totoro-gb-opensource-update2 · C Header · 102 lines · 52 code · 20 blank · 30 comment · 4 complexity · 45b0f50f0f3630caa8820764009a865d MD5 · raw file

  1. /*
  2. * Copyright (C) 2010 Google Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following disclaimer
  12. * in the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Google Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef BindingElement_h
  31. #define BindingElement_h
  32. #include "Attr.h"
  33. #include "BindingSecurity.h"
  34. #include "Element.h"
  35. #include "ExceptionCode.h"
  36. #include <wtf/RefPtr.h>
  37. namespace WebCore {
  38. template <class Binding>
  39. class BindingElement {
  40. public:
  41. static void setAttribute(State<Binding>*, Element*, const AtomicString&, const AtomicString&, ExceptionCode&);
  42. static RefPtr<Attr> setAttributeNode(State<Binding>*, Element*, Attr*, ExceptionCode&);
  43. static void setAttributeNS(State<Binding>*, Element*, const AtomicString&, const AtomicString&, const AtomicString&, ExceptionCode&);
  44. static RefPtr<Attr> setAttributeNodeNS(State<Binding>*, Element*, Attr*, ExceptionCode&);
  45. };
  46. // Implementations of templated methods must be in this file.
  47. template <class Binding>
  48. void BindingElement<Binding>::setAttribute(State<Binding>* state, Element* element, const AtomicString& name, const AtomicString& value, ExceptionCode& ec)
  49. {
  50. ASSERT(element);
  51. if (!BindingSecurity<Binding>::allowSettingSrcToJavascriptURL(state, element, name, value))
  52. return;
  53. element->setAttribute(name, value, ec);
  54. }
  55. template <class Binding>
  56. RefPtr<Attr> BindingElement<Binding>::setAttributeNode(State<Binding>* state, Element* element, Attr* newAttr, ExceptionCode& ec)
  57. {
  58. ASSERT(element);
  59. ASSERT(newAttr);
  60. if (!BindingSecurity<Binding>::allowSettingSrcToJavascriptURL(state, element, newAttr->name(), newAttr->value()))
  61. return 0;
  62. return element->setAttributeNode(newAttr, ec);
  63. }
  64. template <class Binding>
  65. void BindingElement<Binding>::setAttributeNS(State<Binding>* state, Element* element, const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode& ec)
  66. {
  67. ASSERT(element);
  68. if (!BindingSecurity<Binding>::allowSettingSrcToJavascriptURL(state, element, qualifiedName, value))
  69. return;
  70. element->setAttributeNS(namespaceURI, qualifiedName, value, ec);
  71. }
  72. template <class Binding>
  73. RefPtr<Attr> BindingElement<Binding>::setAttributeNodeNS(State<Binding>* state, Element* element, Attr* newAttr, ExceptionCode& ec)
  74. {
  75. ASSERT(element);
  76. ASSERT(newAttr);
  77. if (!BindingSecurity<Binding>::allowSettingSrcToJavascriptURL(state, element, newAttr->name(), newAttr->value()))
  78. return 0;
  79. return element->setAttributeNodeNS(newAttr, ec);
  80. }
  81. } // namespace WebCore
  82. #endif // BindingElement_h