| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
| 3 * Copyright (C) 2006-2016 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 implements Disposable | |
| 23 { | |
| 24 private final Disposer disposer; | |
| 25 protected final long ptr; | |
| 26 | |
| 27 static | |
| 28 { | |
| 29 System.loadLibrary("adblockplus-jni"); | |
| 30 registerNatives(); | |
| 31 } | |
| 32 | |
| 33 public JsEngine(final AppInfo appInfo) | |
| 34 { | |
| 35 this(ctor(appInfo)); | |
| 36 } | |
| 37 | |
| 38 protected JsEngine(final long ptr) | |
| 39 { | |
| 40 this.ptr = ptr; | |
| 41 this.disposer = new Disposer(this, new DisposeWrapper(ptr)); | |
| 42 } | |
| 43 | |
| 44 public void setEventCallback(final String eventName, final EventCallback callb
ack) | |
| 45 { | |
| 46 setEventCallback(this.ptr, eventName, callback.ptr); | |
| 47 } | |
| 48 | |
| 49 public void removeEventCallback(final String eventName) | |
| 50 { | |
| 51 removeEventCallback(this.ptr, eventName); | |
| 52 } | |
| 53 | |
| 54 public JsValue evaluate(final String source, final String filename) | |
| 55 { | |
| 56 return evaluate(this.ptr, source, filename); | |
| 57 } | |
| 58 | |
| 59 public JsValue evaluate(final String source) | |
| 60 { | |
| 61 return evaluate(this.ptr, source, ""); | |
| 62 } | |
| 63 | |
| 64 public void triggerEvent(final String eventName, final List<JsValue> params) | |
| 65 { | |
| 66 final long[] args = new long[params.size()]; | |
| 67 | |
| 68 for (int i = 0; i < args.length; i++) | |
| 69 { | |
| 70 args[i] = params.get(i).ptr; | |
| 71 } | |
| 72 | |
| 73 triggerEvent(this.ptr, eventName, args); | |
| 74 } | |
| 75 | |
| 76 public void triggerEvent(final String eventName) | |
| 77 { | |
| 78 triggerEvent(this.ptr, eventName, null); | |
| 79 } | |
| 80 | |
| 81 public void setDefaultFileSystem(final String basePath) | |
| 82 { | |
| 83 setDefaultFileSystem(this.ptr, basePath); | |
| 84 } | |
| 85 | |
| 86 public void setDefaultLogSystem() | |
| 87 { | |
| 88 setDefaultLogSystem(this.ptr); | |
| 89 } | |
| 90 | |
| 91 public void setLogSystem(final LogSystem logSystem) | |
| 92 { | |
| 93 setLogSystem(this.ptr, logSystem.ptr); | |
| 94 } | |
| 95 | |
| 96 public void setDefaultWebRequest() | |
| 97 { | |
| 98 setDefaultWebRequest(this.ptr); | |
| 99 } | |
| 100 | |
| 101 public void setWebRequest(final WebRequest webRequest) | |
| 102 { | |
| 103 setWebRequest(this.ptr, webRequest.ptr); | |
| 104 } | |
| 105 | |
| 106 public JsValue newValue(final long value) | |
| 107 { | |
| 108 return newValue(this.ptr, value); | |
| 109 } | |
| 110 | |
| 111 public JsValue newValue(final boolean value) | |
| 112 { | |
| 113 return newValue(this.ptr, value); | |
| 114 } | |
| 115 | |
| 116 public JsValue newValue(final String value) | |
| 117 { | |
| 118 return newValue(this.ptr, value); | |
| 119 } | |
| 120 | |
| 121 @Override | |
| 122 public void dispose() | |
| 123 { | |
| 124 this.disposer.dispose(); | |
| 125 } | |
| 126 | |
| 127 private final static class DisposeWrapper implements Disposable | |
| 128 { | |
| 129 private final long ptr; | |
| 130 | |
| 131 public DisposeWrapper(final long ptr) | |
| 132 { | |
| 133 this.ptr = ptr; | |
| 134 } | |
| 135 | |
| 136 @Override | |
| 137 public void dispose() | |
| 138 { | |
| 139 dtor(this.ptr); | |
| 140 } | |
| 141 } | |
| 142 | |
| 143 private final static native void registerNatives(); | |
| 144 | |
| 145 private final static native long ctor(AppInfo appInfo); | |
| 146 | |
| 147 private final static native void setEventCallback(long ptr, String eventName,
long callback); | |
| 148 | |
| 149 private final static native void removeEventCallback(long ptr, String eventNam
e); | |
| 150 | |
| 151 private final static native JsValue evaluate(long ptr, String source, String f
ilename); | |
| 152 | |
| 153 private final static native void triggerEvent(long ptr, String eventName, long
[] args); | |
| 154 | |
| 155 private final static native void setDefaultFileSystem(long ptr, String basePat
h); | |
| 156 | |
| 157 private final static native void setLogSystem(long ptr, long logSystemPtr); | |
| 158 | |
| 159 private final static native void setDefaultLogSystem(long ptr); | |
| 160 | |
| 161 private final static native void setWebRequest(long ptr, long webRequestPtr); | |
| 162 | |
| 163 private final static native void setDefaultWebRequest(long ptr); | |
| 164 | |
| 165 private final static native JsValue newValue(long ptr, long value); | |
| 166 | |
| 167 private final static native JsValue newValue(long ptr, boolean value); | |
| 168 | |
| 169 private final static native JsValue newValue(long ptr, String value); | |
| 170 | |
| 171 private final static native void dtor(long ptr); | |
| 172 } | |
| OLD | NEW |