| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 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/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 package org.adblockplus.libadblockplus; | 18 package org.adblockplus.libadblockplus; |
| 19 | 19 |
| 20 import java.util.List; | 20 import java.util.List; |
| 21 | 21 |
| 22 public final class JsEngine implements Disposable | 22 public final class JsEngine |
| 23 { | 23 { |
| 24 private final Disposer disposer; | |
| 25 protected final long ptr; | 24 protected final long ptr; |
| 26 | 25 |
| 27 static | 26 static |
| 28 { | 27 { |
| 29 System.loadLibrary("adblockplus-jni"); | 28 System.loadLibrary("adblockplus-jni"); |
| 30 registerNatives(); | 29 registerNatives(); |
| 31 } | 30 } |
| 32 | 31 |
| 33 public JsEngine(final AppInfo appInfo, final LogSystem logSystem, final WebReq
uest webRequest, final String basePath) | 32 JsEngine(final long ptr) |
| 34 { | |
| 35 this(ctor(appInfo, logSystem, webRequest, basePath)); | |
| 36 } | |
| 37 | |
| 38 public JsEngine(final AppInfo appInfo) | |
| 39 { | |
| 40 this(appInfo, null, null, null); | |
| 41 } | |
| 42 | |
| 43 protected JsEngine(final long ptr) | |
| 44 { | 33 { |
| 45 this.ptr = ptr; | 34 this.ptr = ptr; |
| 46 this.disposer = new Disposer(this, new DisposeWrapper(ptr)); | |
| 47 } | 35 } |
| 48 | 36 |
| 49 public void setEventCallback(final String eventName, final EventCallback callb
ack) | 37 public void setEventCallback(final String eventName, final EventCallback callb
ack) |
| 50 { | 38 { |
| 51 setEventCallback(this.ptr, eventName, callback.ptr); | 39 setEventCallback(this.ptr, eventName, callback.ptr); |
| 52 } | 40 } |
| 53 | 41 |
| 54 public void removeEventCallback(final String eventName) | 42 public void removeEventCallback(final String eventName) |
| 55 { | 43 { |
| 56 removeEventCallback(this.ptr, eventName); | 44 removeEventCallback(this.ptr, eventName); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 public JsValue newValue(final boolean value) | 79 public JsValue newValue(final boolean value) |
| 92 { | 80 { |
| 93 return newValue(this.ptr, value); | 81 return newValue(this.ptr, value); |
| 94 } | 82 } |
| 95 | 83 |
| 96 public JsValue newValue(final String value) | 84 public JsValue newValue(final String value) |
| 97 { | 85 { |
| 98 return newValue(this.ptr, value); | 86 return newValue(this.ptr, value); |
| 99 } | 87 } |
| 100 | 88 |
| 101 @Override | |
| 102 public void dispose() | |
| 103 { | |
| 104 this.disposer.dispose(); | |
| 105 } | |
| 106 | |
| 107 private final static class DisposeWrapper implements Disposable | |
| 108 { | |
| 109 private final long ptr; | |
| 110 | |
| 111 public DisposeWrapper(final long ptr) | |
| 112 { | |
| 113 this.ptr = ptr; | |
| 114 } | |
| 115 | |
| 116 @Override | |
| 117 public void dispose() | |
| 118 { | |
| 119 dtor(this.ptr); | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 private final static native void registerNatives(); | 89 private final static native void registerNatives(); |
| 124 | 90 |
| 125 private final static native long ctor(AppInfo appInfo, LogSystem logSystem, We
bRequest webRequest, | |
| 126 String basePath); | |
| 127 | |
| 128 private final static native void setEventCallback(long ptr, String eventName,
long callback); | 91 private final static native void setEventCallback(long ptr, String eventName,
long callback); |
| 129 | 92 |
| 130 private final static native void removeEventCallback(long ptr, String eventNam
e); | 93 private final static native void removeEventCallback(long ptr, String eventNam
e); |
| 131 | 94 |
| 132 private final static native JsValue evaluate(long ptr, String source, String f
ilename); | 95 private final static native JsValue evaluate(long ptr, String source, String f
ilename); |
| 133 | 96 |
| 134 private final static native void triggerEvent(long ptr, String eventName, long
[] args); | 97 private final static native void triggerEvent(long ptr, String eventName, long
[] args); |
| 135 | 98 |
| 136 private final static native JsValue newValue(long ptr, long value); | 99 private final static native JsValue newValue(long ptr, long value); |
| 137 | 100 |
| 138 private final static native JsValue newValue(long ptr, boolean value); | 101 private final static native JsValue newValue(long ptr, boolean value); |
| 139 | 102 |
| 140 private final static native JsValue newValue(long ptr, String value); | 103 private final static native JsValue newValue(long ptr, String value); |
| 141 | |
| 142 private final static native void dtor(long ptr); | |
| 143 } | 104 } |
| OLD | NEW |