PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 31#ifndef BindingElement_h
 32#define BindingElement_h
 33
 34#include "Attr.h"
 35#include "BindingSecurity.h"
 36#include "Element.h"
 37#include "ExceptionCode.h"
 38
 39#include <wtf/RefPtr.h>
 40
 41namespace WebCore {
 42
 43template <class Binding>
 44class BindingElement {
 45public:
 46    static void setAttribute(State<Binding>*, Element*, const AtomicString&, const AtomicString&, ExceptionCode&);
 47    static RefPtr<Attr> setAttributeNode(State<Binding>*, Element*, Attr*, ExceptionCode&);
 48    static void setAttributeNS(State<Binding>*, Element*, const AtomicString&, const AtomicString&, const AtomicString&, ExceptionCode&);
 49    static RefPtr<Attr> setAttributeNodeNS(State<Binding>*, Element*, Attr*, ExceptionCode&);
 50};
 51
 52// Implementations of templated methods must be in this file.
 53
 54template <class Binding>
 55void BindingElement<Binding>::setAttribute(State<Binding>* state, Element* element, const AtomicString& name, const AtomicString& value, ExceptionCode& ec)
 56{
 57    ASSERT(element);
 58
 59    if (!BindingSecurity<Binding>::allowSettingSrcToJavascriptURL(state, element, name, value))
 60        return;
 61
 62    element->setAttribute(name, value, ec);
 63}
 64
 65template <class Binding>
 66RefPtr<Attr> BindingElement<Binding>::setAttributeNode(State<Binding>* state, Element* element, Attr* newAttr, ExceptionCode& ec)
 67{
 68    ASSERT(element);
 69    ASSERT(newAttr);
 70
 71    if (!BindingSecurity<Binding>::allowSettingSrcToJavascriptURL(state, element, newAttr->name(), newAttr->value()))
 72        return 0;
 73
 74    return element->setAttributeNode(newAttr, ec);
 75}
 76
 77template <class Binding>
 78void BindingElement<Binding>::setAttributeNS(State<Binding>* state, Element* element, const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode& ec)
 79{
 80    ASSERT(element);
 81
 82    if (!BindingSecurity<Binding>::allowSettingSrcToJavascriptURL(state, element, qualifiedName, value))
 83        return;
 84
 85    element->setAttributeNS(namespaceURI, qualifiedName, value, ec);
 86}
 87
 88template <class Binding>
 89RefPtr<Attr> BindingElement<Binding>::setAttributeNodeNS(State<Binding>* state, Element* element, Attr* newAttr, ExceptionCode& ec)
 90{
 91    ASSERT(element);
 92    ASSERT(newAttr);
 93
 94    if (!BindingSecurity<Binding>::allowSettingSrcToJavascriptURL(state, element, newAttr->name(), newAttr->value()))
 95        return 0;
 96
 97    return element->setAttributeNodeNS(newAttr, ec);
 98}
 99
100} // namespace WebCore
101
102#endif // BindingElement_h