| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
| 3 * Copyright (C) 2006-present eyeo GmbH | |
| 4 * | |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | |
| 6 * it under the terms of the GNU General Public License version 3 as | |
| 7 * published by the Free Software Foundation. | |
| 8 * | |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 * GNU General Public License for more details. | |
| 13 * | |
| 14 * You should have received a copy of the GNU General Public License | |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
| 16 */ | |
| 17 | |
| 18 package org.adblockplus.libadblockplus; | |
| 19 | |
| 20 import java.util.List; | |
| 21 | |
| 22 public final class JsEngine | |
| 23 { | |
| 24 protected final long ptr; | |
| 25 | |
| 26 static | |
| 27 { | |
| 28 System.loadLibrary("adblockplus-jni"); | |
| 29 registerNatives(); | |
| 30 } | |
| 31 | |
| 32 JsEngine(final long ptr) | |
| 33 { | |
| 34 this.ptr = ptr; | |
| 35 } | |
| 36 | |
| 37 public void setEventCallback(final String eventName, final EventCallback callb
ack) | |
| 38 { | |
| 39 setEventCallback(this.ptr, eventName, callback.ptr); | |
| 40 } | |
| 41 | |
| 42 public void removeEventCallback(final String eventName) | |
| 43 { | |
| 44 removeEventCallback(this.ptr, eventName); | |
| 45 } | |
| 46 | |
| 47 public JsValue evaluate(final String source, final String filename) | |
| 48 { | |
| 49 return evaluate(this.ptr, source, filename); | |
| 50 } | |
| 51 | |
| 52 public JsValue evaluate(final String source) | |
| 53 { | |
| 54 return evaluate(this.ptr, source, ""); | |
| 55 } | |
| 56 | |
| 57 public void triggerEvent(final String eventName, final List<JsValue> params) | |
| 58 { | |
| 59 final long[] args = new long[params.size()]; | |
| 60 | |
| 61 for (int i = 0; i < args.length; i++) | |
| 62 { | |
| 63 args[i] = params.get(i).ptr; | |
| 64 } | |
| 65 | |
| 66 triggerEvent(this.ptr, eventName, args); | |
| 67 } | |
| 68 | |
| 69 public void triggerEvent(final String eventName) | |
| 70 { | |
| 71 triggerEvent(this.ptr, eventName, null); | |
| 72 } | |
| 73 | |
| 74 public JsValue newValue(final long value) | |
| 75 { | |
| 76 return newValue(this.ptr, value); | |
| 77 } | |
| 78 | |
| 79 public JsValue newValue(final boolean value) | |
| 80 { | |
| 81 return newValue(this.ptr, value); | |
| 82 } | |
| 83 | |
| 84 public JsValue newValue(final String value) | |
| 85 { | |
| 86 return newValue(this.ptr, value); | |
| 87 } | |
| 88 | |
| 89 private final static native void registerNatives(); | |
| 90 | |
| 91 private final static native void setEventCallback(long ptr, String eventName,
long callback); | |
| 92 | |
| 93 private final static native void removeEventCallback(long ptr, String eventNam
e); | |
| 94 | |
| 95 private final static native JsValue evaluate(long ptr, String source, String f
ilename); | |
| 96 | |
| 97 private final static native void triggerEvent(long ptr, String eventName, long
[] args); | |
| 98 | |
| 99 private final static native JsValue newValue(long ptr, long value); | |
| 100 | |
| 101 private final static native JsValue newValue(long ptr, boolean value); | |
| 102 | |
| 103 private final static native JsValue newValue(long ptr, String value); | |
| 104 } | |
| OLD | NEW |