| 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 public class Platform implements Disposable | |
| 21 { | |
| 22 private final Disposer disposer; | |
| 23 protected final long ptr; | |
| 24 | |
| 25 static | |
| 26 { | |
| 27 System.loadLibrary("adblockplus-jni"); | |
| 28 registerNatives(); | |
| 29 } | |
| 30 | |
| 31 /** | |
| 32 * If an interface parameter value is null then a default implementation is | |
| 33 * chosen. | |
| 34 * If basePath is null then paths are not resolved to a full path, thus | |
| 35 * current working directory is used. | |
| 36 */ | |
| 37 public Platform(final LogSystem logSystem, final WebRequest webRequest, final
String basePath) | |
| 38 { | |
| 39 this(ctor(logSystem, webRequest, basePath)); | |
| 40 } | |
| 41 | |
| 42 protected Platform(final long ptr) | |
| 43 { | |
| 44 this.ptr = ptr; | |
| 45 this.disposer = new Disposer(this, new DisposeWrapper(ptr)); | |
| 46 } | |
| 47 | |
| 48 public void setUpJsEngine(final AppInfo appInfo, final long v8IsolateProviderP
tr) | |
| 49 { | |
| 50 setUpJsEngine(this.ptr, appInfo, v8IsolateProviderPtr); | |
| 51 } | |
| 52 | |
| 53 public void setUpJsEngine(final AppInfo appInfo) | |
| 54 { | |
| 55 setUpJsEngine(appInfo, 0L); | |
| 56 } | |
| 57 | |
| 58 public JsEngine getJsEngine() | |
| 59 { | |
| 60 return new JsEngine(getJsEnginePtr(this.ptr)); | |
| 61 } | |
| 62 | |
| 63 public void setUpFilterEngine(final IsAllowedConnectionCallback isSubscription
DownloadAllowedCallback) | |
| 64 { | |
| 65 setUpFilterEngine(this.ptr, isSubscriptionDownloadAllowedCallback); | |
| 66 } | |
| 67 | |
| 68 public FilterEngine getFilterEngine() | |
| 69 { | |
| 70 // Initially FilterEngine is not constructed when Platform is instantiated | |
| 71 // and in addition FilterEngine is being created asynchronously, the call | |
| 72 // of `ensureFilterEngine` causes a construction of FilterEngine if it's | |
| 73 // not created yet and waits for it. | |
| 74 ensureFilterEngine(this.ptr); | |
| 75 return new FilterEngine(this.ptr); | |
| 76 } | |
| 77 | |
| 78 @Override | |
| 79 public void dispose() | |
| 80 { | |
| 81 this.disposer.dispose(); | |
| 82 } | |
| 83 | |
| 84 private final static class DisposeWrapper implements Disposable | |
| 85 { | |
| 86 private final long ptr; | |
| 87 | |
| 88 public DisposeWrapper(final long ptr) | |
| 89 { | |
| 90 this.ptr = ptr; | |
| 91 } | |
| 92 | |
| 93 @Override | |
| 94 public void dispose() | |
| 95 { | |
| 96 dtor(this.ptr); | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 private final static native void registerNatives(); | |
| 101 | |
| 102 private final static native long ctor(LogSystem logSystem, WebRequest webReque
st, String basePath); | |
| 103 | |
| 104 private final static native void setUpJsEngine(long ptr, AppInfo appInfo, long
v8IsolateProviderPtr); | |
| 105 | |
| 106 private final static native long getJsEnginePtr(long ptr); | |
| 107 | |
| 108 private final static native void setUpFilterEngine(long ptr, IsAllowedConnecti
onCallback isSubscriptionDownloadAllowedCallback); | |
| 109 | |
| 110 private final static native void ensureFilterEngine(long ptr); | |
| 111 | |
| 112 private final static native void dtor(long ptr); | |
| 113 } | |
| OLD | NEW |