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