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

Side by Side Diff: libadblockplus-android-webviewapp/src/org/adblockplus/libadblockplus/android/webviewapp/MainActivity.java

Issue 29671734: Issue 6265 - Create shared AdblockEngine instance in AdblockWebView in background (Closed)
Patch Set: Created Jan. 17, 2018, 11:48 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 22 matching lines...) Expand all
33 import android.widget.EditText; 33 import android.widget.EditText;
34 import android.widget.ProgressBar; 34 import android.widget.ProgressBar;
35 35
36 public class MainActivity extends Activity 36 public class MainActivity extends Activity
37 { 37 {
38 public static final boolean DEVELOPMENT_BUILD = true; 38 public static final boolean DEVELOPMENT_BUILD = true;
39 39
40 // webView can create AdblockEngine instance itself if not passed with `webVie w.setAdblockEngine()` 40 // webView can create AdblockEngine instance itself if not passed with `webVie w.setAdblockEngine()`
41 public static final boolean USE_EXTERNAL_ADBLOCKENGINE = true; 41 public static final boolean USE_EXTERNAL_ADBLOCKENGINE = true;
42 42
43 // adblock retain() may be long-running, pass `true` to do it in background th read
44 public static final boolean ADBLOCKENGINE_RETAIN_ASYNC = true;
45
46 private ProgressBar progress; 43 private ProgressBar progress;
47 private EditText url; 44 private EditText url;
48 private Button ok; 45 private Button ok;
49 private Button back; 46 private Button back;
50 private Button forward; 47 private Button forward;
51 private Button settings; 48 private Button settings;
52 49
53 private AdblockWebView webView; 50 private AdblockWebView webView;
54 51
55 @Override 52 @Override
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 191
195 private void navigateSettings() 192 private void navigateSettings()
196 { 193 {
197 startActivity(new Intent(this, SettingsActivity.class)); 194 startActivity(new Intent(this, SettingsActivity.class));
198 } 195 }
199 196
200 private void initAdblockWebView() 197 private void initAdblockWebView()
201 { 198 {
202 if (USE_EXTERNAL_ADBLOCKENGINE) 199 if (USE_EXTERNAL_ADBLOCKENGINE)
203 { 200 {
204 // external adblockEngine 201 // external AdblockEngine
205 AdblockHelper.get().retain(ADBLOCKENGINE_RETAIN_ASYNC); 202 webView.setProvider(AdblockHelper.get().getProvider());
206
207 if (!ADBLOCKENGINE_RETAIN_ASYNC)
208 {
209 webView.setAdblockEngine(AdblockHelper.get().getEngine());
210 }
211 } 203 }
212 else 204 else
213 { 205 {
214 // AdblockWebView will create internal AdblockEngine instance 206 // AdblockWebView will create internal AdblockEngine instance
215 } 207 }
216 } 208 }
217 209
218 private void hideSoftwareKeyboard() 210 private void hideSoftwareKeyboard()
219 { 211 {
220 InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_S ERVICE); 212 InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_S ERVICE);
(...skipping 23 matching lines...) Expand all
244 if (!url.startsWith("http")) 236 if (!url.startsWith("http"))
245 url = "http://" + url; 237 url = "http://" + url;
246 238
247 // make sure url is valid URL 239 // make sure url is valid URL
248 return url; 240 return url;
249 } 241 }
250 242
251 private void loadUrl() 243 private void loadUrl()
252 { 244 {
253 hideSoftwareKeyboard(); 245 hideSoftwareKeyboard();
254
255 // if retained with `true` we need to make sure it's ready now
256 if (USE_EXTERNAL_ADBLOCKENGINE && ADBLOCKENGINE_RETAIN_ASYNC)
257 {
258 AdblockHelper.get().waitForReady();
259 webView.setAdblockEngine(AdblockHelper.get().getEngine());
260 }
261 webView.loadUrl(prepareUrl(url.getText().toString())); 246 webView.loadUrl(prepareUrl(url.getText().toString()));
262 } 247 }
263 248
264 @Override 249 @Override
265 protected void onDestroy() 250 protected void onDestroy()
266 { 251 {
267 webView.dispose(new Runnable() 252 webView.dispose(null);
268 {
269 @Override
270 public void run()
271 {
272 if (USE_EXTERNAL_ADBLOCKENGINE)
273 {
274 AdblockHelper.get().release();
275 }
276 }
277 });
278 253
279 super.onDestroy(); 254 super.onDestroy();
280 } 255 }
281 } 256 }
OLDNEW

Powered by Google App Engine
This is Rietveld