1 /* 2 * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #undef IMPL 27 28 #include "config.h" 29 30 #include "DOMException.h" 31 #include <WebCore/Attr.h> 32 #include <WebCore/NamedNodeMap.h> 33 #include <WebCore/Node.h> 34 #include <WebCore/JSMainThreadExecState.h> 35 36 #include <wtf/RefPtr.h> 37 #include <wtf/GetPtr.h> 38 39 #include "JavaDOMUtils.h" 40 #include <wtf/java/JavaEnv.h> 41 42 using namespace WebCore; 43 44 extern "C" { 45 46 #define IMPL (static_cast<NamedNodeMap*>(jlong_to_ptr(peer))) 47 48 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_NamedNodeMapImpl_dispose(JNIEnv*, jclass, jlong peer) 49 { 50 IMPL->deref(); 51 } 52 53 54 // Attributes 55 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_NamedNodeMapImpl_getLengthImpl(JNIEnv*, jclass, jlong peer) 56 { 57 WebCore::JSMainThreadNullState state; 58 return IMPL->length(); 59 } 60 61 62 // Functions 63 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_NamedNodeMapImpl_getNamedItemImpl(JNIEnv* env, jclass, jlong peer 64 , jstring name) 65 { 66 WebCore::JSMainThreadNullState state; 67 return JavaReturn<Node>(env, WTF::getPtr(IMPL->getNamedItem(String(env, name)))); 68 } 69 70 71 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_NamedNodeMapImpl_setNamedItemImpl(JNIEnv* env, jclass, jlong peer 72 , jlong node) 73 { 74 WebCore::JSMainThreadNullState state; 75 if (!node) { 76 raiseTypeErrorException(env); 77 return 0; 78 } 79 auto& coreNode = *static_cast<Node*>(jlong_to_ptr(node)); 80 if (!is<WebCore::Attr>(coreNode)) { 81 raiseTypeErrorException(env); 82 return 0; 83 } 84 return JavaReturn<Node>(env, WTF::getPtr(raiseOnDOMError(env, IMPL->setNamedItem(downcast<WebCore::Attr>(coreNode))))); 85 } 86 87 88 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_NamedNodeMapImpl_removeNamedItemImpl(JNIEnv* env, jclass, jlong peer 89 , jstring name) 90 { 91 WebCore::JSMainThreadNullState state; 92 return JavaReturn<Node>(env, WTF::getPtr(raiseOnDOMError(env, IMPL->removeNamedItem(String(env, name))))); 93 } 94 95 96 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_NamedNodeMapImpl_itemImpl(JNIEnv* env, jclass, jlong peer 97 , jint index) 98 { 99 WebCore::JSMainThreadNullState state; 100 return JavaReturn<Node>(env, WTF::getPtr(IMPL->item(index))); 101 } 102 103 104 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_NamedNodeMapImpl_getNamedItemNSImpl(JNIEnv* env, jclass, jlong peer 105 , jstring namespaceURI 106 , jstring localName) 107 { 108 WebCore::JSMainThreadNullState state; 109 return JavaReturn<Node>(env, WTF::getPtr(IMPL->getNamedItemNS(String(env, namespaceURI) 110 , String(env, localName)))); 111 } 112 113 114 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_NamedNodeMapImpl_setNamedItemNSImpl(JNIEnv* env, jclass clazz, jlong peer 115 , jlong node) 116 { 117 return Java_com_sun_webkit_dom_NamedNodeMapImpl_setNamedItemImpl(env, clazz, peer, node); 118 } 119 120 121 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_NamedNodeMapImpl_removeNamedItemNSImpl(JNIEnv* env, jclass, jlong peer 122 , jstring namespaceURI 123 , jstring localName) 124 { 125 WebCore::JSMainThreadNullState state; 126 return JavaReturn<Node>(env, WTF::getPtr(raiseOnDOMError(env, IMPL->removeNamedItemNS(String(env, namespaceURI) 127 , String(env, localName))))); 128 } 129 130 131 }