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 <WebCore/HTMLCollection.h>
  31 #include <WebCore/HTMLDocument.h>
  32 #include <WebCore/JSMainThreadExecState.h>
  33 
  34 #include <wtf/RefPtr.h>
  35 #include <wtf/GetPtr.h>
  36 
  37 #include "JavaDOMUtils.h"
  38 #include <wtf/java/JavaEnv.h>
  39 
  40 using namespace WebCore;
  41 
  42 extern "C" {
  43 
  44 #define IMPL (static_cast<HTMLDocument*>(jlong_to_ptr(peer)))
  45 
  46 
  47 // Attributes
  48 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_getEmbedsImpl(JNIEnv* env, jclass, jlong peer)
  49 {
  50     WebCore::JSMainThreadNullState state;
  51     return JavaReturn<HTMLCollection>(env, WTF::getPtr(IMPL->embeds()));
  52 }
  53 
  54 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_getPluginsImpl(JNIEnv* env, jclass, jlong peer)
  55 {
  56     WebCore::JSMainThreadNullState state;
  57     return JavaReturn<HTMLCollection>(env, WTF::getPtr(IMPL->plugins()));
  58 }
  59 
  60 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_getScriptsImpl(JNIEnv* env, jclass, jlong peer)
  61 {
  62     WebCore::JSMainThreadNullState state;
  63     return JavaReturn<HTMLCollection>(env, WTF::getPtr(IMPL->scripts()));
  64 }
  65 
  66 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_getWidthImpl(JNIEnv*, jclass, jlong peer)
  67 {
  68     WebCore::JSMainThreadNullState state;
  69     return IMPL->width();
  70 }
  71 
  72 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_getHeightImpl(JNIEnv*, jclass, jlong peer)
  73 {
  74     WebCore::JSMainThreadNullState state;
  75     return IMPL->height();
  76 }
  77 
  78 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_getDirImpl(JNIEnv* env, jclass, jlong peer)
  79 {
  80     WebCore::JSMainThreadNullState state;
  81     return JavaReturn<String>(env, IMPL->dir());
  82 }
  83 
  84 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_setDirImpl(JNIEnv* env, jclass, jlong peer, jstring value)
  85 {
  86     WebCore::JSMainThreadNullState state;
  87     IMPL->setDir(String(env, value));
  88 }
  89 
  90 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_getDesignModeImpl(JNIEnv* env, jclass, jlong peer)
  91 {
  92     WebCore::JSMainThreadNullState state;
  93     return JavaReturn<String>(env, IMPL->designMode());
  94 }
  95 
  96 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_setDesignModeImpl(JNIEnv* env, jclass, jlong peer, jstring value)
  97 {
  98     WebCore::JSMainThreadNullState state;
  99     IMPL->setDesignMode(String(env, value));
 100 }
 101 
 102 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_getCompatModeImpl(JNIEnv* env, jclass, jlong peer)
 103 {
 104     WebCore::JSMainThreadNullState state;
 105     return JavaReturn<String>(env, IMPL->compatMode());
 106 }
 107 
 108 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_getBgColorImpl(JNIEnv* env, jclass, jlong peer)
 109 {
 110     WebCore::JSMainThreadNullState state;
 111     return JavaReturn<String>(env, IMPL->bgColor());
 112 }
 113 
 114 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_setBgColorImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 115 {
 116     WebCore::JSMainThreadNullState state;
 117     IMPL->setBgColor(String(env, value));
 118 }
 119 
 120 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_getFgColorImpl(JNIEnv* env, jclass, jlong peer)
 121 {
 122     WebCore::JSMainThreadNullState state;
 123     return JavaReturn<String>(env, IMPL->fgColor());
 124 }
 125 
 126 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_setFgColorImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 127 {
 128     WebCore::JSMainThreadNullState state;
 129     IMPL->setFgColor(String(env, value));
 130 }
 131 
 132 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_getAlinkColorImpl(JNIEnv* env, jclass, jlong peer)
 133 {
 134     WebCore::JSMainThreadNullState state;
 135     return JavaReturn<String>(env, IMPL->alinkColor());
 136 }
 137 
 138 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_setAlinkColorImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 139 {
 140     WebCore::JSMainThreadNullState state;
 141     IMPL->setAlinkColor(String(env, value));
 142 }
 143 
 144 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_getLinkColorImpl(JNIEnv* env, jclass, jlong peer)
 145 {
 146     WebCore::JSMainThreadNullState state;
 147     return JavaReturn<String>(env, IMPL->linkColorForBindings());
 148 }
 149 
 150 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_setLinkColorImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 151 {
 152     WebCore::JSMainThreadNullState state;
 153     IMPL->setLinkColorForBindings(String(env, value));
 154 }
 155 
 156 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_getVlinkColorImpl(JNIEnv* env, jclass, jlong peer)
 157 {
 158     WebCore::JSMainThreadNullState state;
 159     return JavaReturn<String>(env, IMPL->vlinkColor());
 160 }
 161 
 162 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_setVlinkColorImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 163 {
 164     WebCore::JSMainThreadNullState state;
 165     IMPL->setVlinkColor(String(env, value));
 166 }
 167 
 168 
 169 // Functions
 170 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_openImpl(JNIEnv*, jclass, jlong peer)
 171 {
 172     WebCore::JSMainThreadNullState state;
 173     IMPL->open();
 174 }
 175 
 176 
 177 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_closeImpl(JNIEnv*, jclass, jlong peer)
 178 {
 179     WebCore::JSMainThreadNullState state;
 180     IMPL->close();
 181 }
 182 
 183 
 184 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_writeImpl(JNIEnv* env, jclass, jlong peer
 185     , jstring text)
 186 {
 187     WebCore::JSMainThreadNullState state;
 188     IMPL->write(nullptr, { String(env, text) });
 189 }
 190 
 191 
 192 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_writelnImpl(JNIEnv* env, jclass, jlong peer
 193     , jstring text)
 194 {
 195     WebCore::JSMainThreadNullState state;
 196     IMPL->writeln(nullptr, { String(env, text) });
 197 }
 198 
 199 
 200 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_clearImpl(JNIEnv*, jclass, jlong peer)
 201 {
 202     WebCore::JSMainThreadNullState state;
 203     IMPL->clear();
 204 }
 205 
 206 
 207 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_captureEventsImpl(JNIEnv*, jclass, jlong peer)
 208 {
 209     WebCore::JSMainThreadNullState state;
 210     IMPL->captureEvents();
 211 }
 212 
 213 
 214 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLDocumentImpl_releaseEventsImpl(JNIEnv*, jclass, jlong peer)
 215 {
 216     WebCore::JSMainThreadNullState state;
 217     IMPL->releaseEvents();
 218 }
 219 
 220 
 221 }