1 /* 2 * Copyright (c) 2013, 2018, 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/DocumentFragment.h> 32 #include <WebCore/Element.h> 33 #include <WebCore/HTMLCollection.h> 34 #include <WebCore/NodeList.h> 35 #include <WebCore/JSMainThreadExecState.h> 36 37 #include <wtf/RefPtr.h> 38 #include <wtf/GetPtr.h> 39 40 #include "JavaDOMUtils.h" 41 #include <wtf/java/JavaEnv.h> 42 43 using namespace WebCore; 44 45 extern "C" { 46 47 #define IMPL (static_cast<DocumentFragment*>(jlong_to_ptr(peer))) 48 49 50 // Attributes 51 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_DocumentFragmentImpl_getChildrenImpl(JNIEnv* env, jclass, jlong peer) 52 { 53 WebCore::JSMainThreadNullState state; 54 return JavaReturn<HTMLCollection>(env, WTF::getPtr(IMPL->children())); 55 } 56 57 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_DocumentFragmentImpl_getFirstElementChildImpl(JNIEnv* env, jclass, jlong peer) 58 { 59 WebCore::JSMainThreadNullState state; 60 return JavaReturn<Element>(env, WTF::getPtr(IMPL->firstElementChild())); 61 } 62 63 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_DocumentFragmentImpl_getLastElementChildImpl(JNIEnv* env, jclass, jlong peer) 64 { 65 WebCore::JSMainThreadNullState state; 66 return JavaReturn<Element>(env, WTF::getPtr(IMPL->lastElementChild())); 67 } 68 69 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_DocumentFragmentImpl_getChildElementCountImpl(JNIEnv*, jclass, jlong peer) 70 { 71 WebCore::JSMainThreadNullState state; 72 return IMPL->childElementCount(); 73 } 74 75 76 // Functions 77 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_DocumentFragmentImpl_getElementByIdImpl(JNIEnv* env, jclass, jlong peer 78 , jstring elementId) 79 { 80 WebCore::JSMainThreadNullState state; 81 return JavaReturn<Element>(env, WTF::getPtr(IMPL->getElementById(String(env, elementId)))); 82 } 83 84 85 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_DocumentFragmentImpl_querySelectorImpl(JNIEnv* env, jclass, jlong peer 86 , jstring selectors) 87 { 88 WebCore::JSMainThreadNullState state; 89 return JavaReturn<Element>(env, WTF::getPtr(raiseOnDOMError(env, IMPL->querySelector(String(env, selectors))))); 90 } 91 92 93 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_DocumentFragmentImpl_querySelectorAllImpl(JNIEnv* env, jclass, jlong peer 94 , jstring selectors) 95 { 96 WebCore::JSMainThreadNullState state; 97 return JavaReturn<NodeList>(env, WTF::getPtr(raiseOnDOMError(env, IMPL->querySelectorAll(String(env, selectors))))); 98 } 99 100 101 }