Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java

Issue 29556582: Issue 5643 - Make v8::Isolate injectable into JsEngine (Closed)
Patch Set: Using JniLongToTypePtr for casting Created Sept. 28, 2017, 8:55 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 private Context context; 53 private Context context;
54 private String basePath; 54 private String basePath;
55 private boolean developmentBuild; 55 private boolean developmentBuild;
56 private String settingsPreferenceName; 56 private String settingsPreferenceName;
57 private String preloadedPreferenceName; 57 private String preloadedPreferenceName;
58 private Map<String, Integer> urlToResourceIdMap; 58 private Map<String, Integer> urlToResourceIdMap;
59 private AdblockEngine engine; 59 private AdblockEngine engine;
60 private AdblockSettingsStorage storage; 60 private AdblockSettingsStorage storage;
61 private CountDownLatch engineCreated; 61 private CountDownLatch engineCreated;
62 private Long v8IsolatePtr;
62 63
63 /* 64 /*
64 Simple ARC management for AdblockEngine 65 Simple ARC management for AdblockEngine
65 Use `retain` and `release` 66 Use `retain` and `release`
66 */ 67 */
67 68
68 private AtomicInteger referenceCounter = new AtomicInteger(0); 69 private AtomicInteger referenceCounter = new AtomicInteger(0);
69 70
70 // singleton 71 // singleton
71 protected AdblockHelper() 72 protected AdblockHelper()
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 * @param preferenceName Shared Preferences name to store intercepted requests stats 125 * @param preferenceName Shared Preferences name to store intercepted requests stats
125 * @param urlToResourceIdMap 126 * @param urlToResourceIdMap
126 */ 127 */
127 public AdblockHelper preloadSubscriptions(String preferenceName, Map<String, I nteger> urlToResourceIdMap) 128 public AdblockHelper preloadSubscriptions(String preferenceName, Map<String, I nteger> urlToResourceIdMap)
128 { 129 {
129 this.preloadedPreferenceName = preferenceName; 130 this.preloadedPreferenceName = preferenceName;
130 this.urlToResourceIdMap = urlToResourceIdMap; 131 this.urlToResourceIdMap = urlToResourceIdMap;
131 return this; 132 return this;
132 } 133 }
133 134
135 public void useV8Isolate(long ptr)
136 {
137 this.v8IsolatePtr = ptr;
138 }
139
134 private void createAdblock() 140 private void createAdblock()
135 { 141 {
136 ConnectivityManager connectivityManager = 142 ConnectivityManager connectivityManager =
137 (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVIC E); 143 (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVIC E);
138 IsAllowedConnectionCallback isAllowedConnectionCallback = new IsAllowedConne ctionCallbackImpl(connectivityManager); 144 IsAllowedConnectionCallback isAllowedConnectionCallback = new IsAllowedConne ctionCallbackImpl(connectivityManager);
139 145
140 Log.d(TAG, "Creating adblock engine ..."); 146 Log.d(TAG, "Creating adblock engine ...");
141 147
142 // read and apply current settings 148 // read and apply current settings
143 SharedPreferences settingsPrefs = context.getSharedPreferences( 149 SharedPreferences settingsPrefs = context.getSharedPreferences(
144 settingsPreferenceName, 150 settingsPreferenceName,
145 Context.MODE_PRIVATE); 151 Context.MODE_PRIVATE);
146 storage = new SharedPrefsStorage(settingsPrefs); 152 storage = new SharedPrefsStorage(settingsPrefs);
147 153
148 AdblockEngine.Builder builder = AdblockEngine 154 AdblockEngine.Builder builder = AdblockEngine
149 .builder( 155 .builder(
150 AdblockEngine.generateAppInfo(context, developmentBuild), 156 AdblockEngine.generateAppInfo(context, developmentBuild),
151 basePath) 157 basePath)
152 .setIsAllowedConnectionCallback(isAllowedConnectionCallback) 158 .setIsAllowedConnectionCallback(isAllowedConnectionCallback)
153 .enableElementHiding(true); 159 .enableElementHiding(true);
154 160
161 if (v8IsolatePtr != null)
162 {
163 builder.useV8Isolate(v8IsolatePtr);
164 }
165
155 // if preloaded subscriptions provided 166 // if preloaded subscriptions provided
156 if (preloadedPreferenceName != null) 167 if (preloadedPreferenceName != null)
157 { 168 {
158 SharedPreferences preloadedSubscriptionsPrefs = context.getSharedPreferenc es( 169 SharedPreferences preloadedSubscriptionsPrefs = context.getSharedPreferenc es(
159 preloadedPreferenceName, 170 preloadedPreferenceName,
160 Context.MODE_PRIVATE); 171 Context.MODE_PRIVATE);
161 builder.preloadSubscriptions( 172 builder.preloadSubscriptions(
162 context, 173 context,
163 urlToResourceIdMap, 174 urlToResourceIdMap,
164 new AndroidWebRequestResourceWrapper.SharedPrefsStorage(preloadedSubscri ptionsPrefs)); 175 new AndroidWebRequestResourceWrapper.SharedPrefsStorage(preloadedSubscri ptionsPrefs));
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 engineCreated.countDown(); 296 engineCreated.countDown();
286 engineCreated = null; 297 engineCreated = null;
287 } 298 }
288 else 299 else
289 { 300 {
290 disposeAdblock(); 301 disposeAdblock();
291 } 302 }
292 } 303 }
293 } 304 }
294 } 305 }
OLDNEW

Powered by Google App Engine
This is Rietveld