Left: | ||
Right: |
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 final String locale = Locale.getDefault().toString().replace('_', '-'); | 96 final String locale = Locale.getDefault().toString().replace('_', '-'); |
97 | 97 |
98 return AppInfo.builder() | 98 return AppInfo.builder() |
99 .setVersion(version) | 99 .setVersion(version) |
100 .setApplicationVersion(sdkVersion) | 100 .setApplicationVersion(sdkVersion) |
101 .setLocale(locale) | 101 .setLocale(locale) |
102 .setDevelopmentBuild(developmentBuild) | 102 .setDevelopmentBuild(developmentBuild) |
103 .build(); | 103 .build(); |
104 } | 104 } |
105 | 105 |
106 public static final UpdateAvailableCallback UPDATE_AVAILABLE_CALLBACK = | |
107 new UpdateAvailableCallback() | |
108 { | |
109 @Override | |
110 public void updateAvailableCallback(String url) | |
111 { | |
112 Log.d(TAG, "Update available for " + url); | |
113 } | |
114 }; | |
115 | |
116 public static final UpdateCheckDoneCallback UPDATE_CHECK_DONE_CALLBACK = | |
117 new UpdateCheckDoneCallback() | |
118 { | |
119 @Override | |
120 public void updateCheckDoneCallback(String error) | |
121 { | |
122 Log.d(TAG, "Update check done, error: " + error); | |
123 } | |
124 }; | |
125 | |
126 public static final ShowNotificationCallback SHOW_NOTIFICATION_CALLBACK = | |
127 new ShowNotificationCallback() | |
128 { | |
129 @Override | |
130 public void showNotificationCallback(Notification jsValue) | |
131 { | |
132 Log.d(TAG, "Notification: " + jsValue); | |
133 } | |
134 }; | |
135 | |
136 public static final FilterChangeCallback FILTER_CHANGE_CALLBACK = | |
137 new FilterChangeCallback() | |
138 { | |
139 @Override | |
140 public void filterChangeCallback(String action, JsValue jsValue) | |
141 { | |
142 Log.d(TAG, "Filter changed: " + action + (!jsValue.isUndefined() ? ", " + jsValue : "")); | |
143 } | |
144 }; | |
145 | |
146 public static AdblockEngine create(final Context context, final AppInfo appInf o, | 106 public static AdblockEngine create(final Context context, final AppInfo appInf o, |
147 final String basePath, boolean enableElemhi de, | 107 final String basePath, boolean enableElemhi de, |
148 UpdateAvailableCallback updateAvailableCall back, | 108 UpdateAvailableCallback updateAvailableCall back, |
149 UpdateCheckDoneCallback updateCheckDoneCall back, | 109 UpdateCheckDoneCallback updateCheckDoneCall back, |
150 ShowNotificationCallback showNotificationCa llback, | 110 ShowNotificationCallback showNotificationCa llback, |
151 FilterChangeCallback filterChangeCallback) | 111 FilterChangeCallback filterChangeCallback) |
152 { | 112 { |
153 Log.w(TAG, "Create"); | 113 Log.w(TAG, "Create"); |
154 | 114 |
155 final AdblockEngine engine = new AdblockEngine(context, enableElemhide); | 115 final AdblockEngine engine = new AdblockEngine(context, enableElemhide); |
(...skipping 30 matching lines...) Expand all Loading... | |
186 } | 146 } |
187 | 147 |
188 engine.webRequest.updateSubscriptionURLs(engine.filterEngine); | 148 engine.webRequest.updateSubscriptionURLs(engine.filterEngine); |
189 | 149 |
190 return engine; | 150 return engine; |
191 } | 151 } |
192 | 152 |
193 public static AdblockEngine create(final Context context, final AppInfo appInf o, | 153 public static AdblockEngine create(final Context context, final AppInfo appInf o, |
194 final String basePath, boolean elemhideEnab led) | 154 final String basePath, boolean elemhideEnab led) |
195 { | 155 { |
196 return create(context, appInfo, basePath, elemhideEnabled, | 156 return create(context, appInfo, basePath, elemhideEnabled, null, null, null, null); |
diegocarloslima
2016/11/04 10:35:15
Is this callback cleanup related to the crash? If
anton
2016/11/07 07:35:14
Yes, it's related as since we use smart pointers c
Felix Dahlke
2016/11/18 06:56:55
So what if the user passes these callback objects
| |
197 UPDATE_AVAILABLE_CALLBACK, UPDATE_CHECK_DONE_CALLBACK, | |
198 SHOW_NOTIFICATION_CALLBACK, FILTER_CHANGE_CALLBACK); | |
199 } | 157 } |
200 | 158 |
201 public void dispose() | 159 public void dispose() |
202 { | 160 { |
203 Log.w(TAG, "Dispose"); | 161 Log.w(TAG, "Dispose"); |
204 | 162 |
205 // Safe disposing (just in case) | |
206 if (this.filterEngine != null) | |
207 { | |
208 this.filterEngine.dispose(); | |
209 this.filterEngine = null; | |
210 } | |
211 | |
212 if (this.jsEngine != null) | |
213 { | |
214 this.jsEngine.dispose(); | |
215 this.jsEngine = null; | |
216 } | |
217 | |
218 if (this.logSystem != null) | 163 if (this.logSystem != null) |
219 { | 164 { |
220 this.logSystem.dispose(); | 165 this.logSystem.dispose(); |
221 this.logSystem = null; | 166 this.logSystem = null; |
222 } | 167 } |
223 | 168 |
224 if (this.webRequest != null) | 169 if (this.webRequest != null) |
225 { | 170 { |
226 this.webRequest.dispose(); | 171 this.webRequest.dispose(); |
227 this.webRequest = null; | 172 this.webRequest = null; |
228 } | 173 } |
229 | 174 |
230 if (this.updateAvailableCallback != null) | 175 if (this.updateAvailableCallback != null) |
231 { | 176 { |
177 if (this.filterEngine != null) | |
178 { | |
179 this.filterEngine.removeUpdateAvailableCallback(); | |
180 } | |
181 | |
232 this.updateAvailableCallback.dispose(); | 182 this.updateAvailableCallback.dispose(); |
233 this.updateAvailableCallback = null; | 183 this.updateAvailableCallback = null; |
234 } | 184 } |
235 | 185 |
236 if (this.updateCheckDoneCallback != null) | 186 if (this.updateCheckDoneCallback != null) |
237 { | 187 { |
238 this.updateCheckDoneCallback.dispose(); | 188 this.updateCheckDoneCallback.dispose(); |
239 this.updateCheckDoneCallback = null; | 189 this.updateCheckDoneCallback = null; |
240 } | 190 } |
241 | 191 |
242 if (this.filterChangeCallback != null) | 192 if (this.filterChangeCallback != null) |
243 { | 193 { |
194 if (this.filterEngine != null) | |
195 { | |
196 this.filterEngine.removeFilterChangeCallback(); | |
197 } | |
198 | |
244 this.filterChangeCallback.dispose(); | 199 this.filterChangeCallback.dispose(); |
245 this.filterChangeCallback = null; | 200 this.filterChangeCallback = null; |
246 } | 201 } |
247 | 202 |
248 if (this.showNotificationCallback != null) | 203 if (this.showNotificationCallback != null) |
249 { | 204 { |
205 if (this.filterEngine != null) | |
206 { | |
207 this.filterEngine.removeShowNotificationCallback(); | |
208 } | |
209 | |
250 this.showNotificationCallback.dispose(); | 210 this.showNotificationCallback.dispose(); |
251 this.showNotificationCallback = null; | 211 this.showNotificationCallback = null; |
252 } | 212 } |
213 | |
214 // Safe disposing (just in case) | |
215 if (this.filterEngine != null) | |
216 { | |
217 this.filterEngine.dispose(); | |
218 this.filterEngine = null; | |
219 } | |
220 | |
221 if (this.jsEngine != null) | |
222 { | |
223 this.jsEngine.dispose(); | |
224 this.jsEngine = null; | |
225 } | |
253 } | 226 } |
254 | 227 |
255 public boolean isFirstRun() | 228 public boolean isFirstRun() |
256 { | 229 { |
257 return this.filterEngine.isFirstRun(); | 230 return this.filterEngine.isFirstRun(); |
258 } | 231 } |
259 | 232 |
260 public boolean isElemhideEnabled() | 233 public boolean isElemhideEnabled() |
261 { | 234 { |
262 return this.elemhideEnabled; | 235 return this.elemhideEnabled; |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
498 public void setWhitelistedDomains(List<String> domains) | 471 public void setWhitelistedDomains(List<String> domains) |
499 { | 472 { |
500 this.whitelistedDomains = domains; | 473 this.whitelistedDomains = domains; |
501 } | 474 } |
502 | 475 |
503 public List<String> getWhitelistedDomains() | 476 public List<String> getWhitelistedDomains() |
504 { | 477 { |
505 return whitelistedDomains; | 478 return whitelistedDomains; |
506 } | 479 } |
507 } | 480 } |
OLD | NEW |