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

Side by Side Diff: libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java

Issue 29677555: Issue 6299 - Avoid main thread lock on URL loading (Closed)
Patch Set: added "final" for domain Created Jan. 23, 2018, 10:33 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 private boolean adblockEnabled = true; 98 private boolean adblockEnabled = true;
99 private boolean debugMode; 99 private boolean debugMode;
100 private AdblockEngineProvider provider; 100 private AdblockEngineProvider provider;
101 private Integer loadError; 101 private Integer loadError;
102 private int allowDrawDelay = ALLOW_DRAW_DELAY; 102 private int allowDrawDelay = ALLOW_DRAW_DELAY;
103 private WebChromeClient extWebChromeClient; 103 private WebChromeClient extWebChromeClient;
104 private WebViewClient extWebViewClient; 104 private WebViewClient extWebViewClient;
105 private WebViewClient intWebViewClient; 105 private WebViewClient intWebViewClient;
106 private Map<String, String> url2Referrer = Collections.synchronizedMap(new Has hMap<String, String>()); 106 private Map<String, String> url2Referrer = Collections.synchronizedMap(new Has hMap<String, String>());
107 private String url; 107 private String url;
108 private String domain;
109 private String injectJs; 108 private String injectJs;
110 private CountDownLatch elemHideLatch; 109 private CountDownLatch elemHideLatch;
111 private String elemHideSelectorsString; 110 private String elemHideSelectorsString;
112 private Object elemHideThreadLockObject = new Object(); 111 private Object elemHideThreadLockObject = new Object();
113 private ElemHideThread elemHideThread; 112 private ElemHideThread elemHideThread;
114 private boolean loading; 113 private boolean loading;
115 private volatile boolean elementsHidden = false; 114 private volatile boolean elementsHidden = false;
116 private final Handler handler = new Handler(); 115 private final Handler handler = new Handler();
117 116
118 // used to prevent user see flickering for elements to hide 117 // used to prevent user see flickering for elements to hide
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 boolean isXmlHttpRequest, String[] referrerChainArray) 819 boolean isXmlHttpRequest, String[] referrerChainArray)
821 { 820 {
822 // if dispose() was invoke, but the page is still loading then just let it go 821 // if dispose() was invoke, but the page is still loading then just let it go
823 if (provider.getCounter() == 0) 822 if (provider.getCounter() == 0)
824 { 823 {
825 e("FilterEngine already disposed, allow loading"); 824 e("FilterEngine already disposed, allow loading");
826 825
827 // allow loading by returning null 826 // allow loading by returning null
828 return null; 827 return null;
829 } 828 }
829 else
830 {
831 provider.waitForReady();
832 }
830 833
831 if (isMainFrame) 834 if (isMainFrame)
832 { 835 {
833 // never blocking main frame requests, just subrequests 836 // never blocking main frame requests, just subrequests
834 w(url + " is main frame, allow loading"); 837 w(url + " is main frame, allow loading");
835 838
836 // allow loading by returning null 839 // allow loading by returning null
837 return null; 840 return null;
838 } 841 }
839 842
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 { 973 {
971 try 974 try
972 { 975 {
973 if (provider.getCounter() == 0) 976 if (provider.getCounter() == 0)
974 { 977 {
975 w("FilterEngine already disposed"); 978 w("FilterEngine already disposed");
976 selectorsString = EMPTY_ELEMHIDE_ARRAY_STRING; 979 selectorsString = EMPTY_ELEMHIDE_ARRAY_STRING;
977 } 980 }
978 else 981 else
979 { 982 {
983 provider.waitForReady();
980 String[] referrers = new String[] 984 String[] referrers = new String[]
981 { 985 {
982 url 986 url
983 }; 987 };
984 988
985 List<Subscription> subscriptions = provider 989 List<Subscription> subscriptions = provider
986 .getEngine() 990 .getEngine()
987 .getFilterEngine() 991 .getFilterEngine()
988 .getListedSubscriptions(); 992 .getListedSubscriptions();
989 993
(...skipping 11 matching lines...) Expand all
1001 } 1005 }
1002 } 1006 }
1003 finally 1007 finally
1004 { 1008 {
1005 for (Subscription eachSubscription : subscriptions) 1009 for (Subscription eachSubscription : subscriptions)
1006 { 1010 {
1007 eachSubscription.dispose(); 1011 eachSubscription.dispose();
1008 } 1012 }
1009 } 1013 }
1010 1014
1011 d("Requesting elemhide selectors from AdblockEngine for " + url + " in " + this); 1015 final String domain = provider.getEngine().getFilterEngine().getHostFr omURL(url);
1012 List<String> selectors = provider 1016 if (domain == null)
1013 .getEngine() 1017 {
1014 .getElementHidingSelectors(url, domain, referrers); 1018 e("Failed to extract domain from " + url);
1019 selectorsString = EMPTY_ELEMHIDE_ARRAY_STRING;
1020 }
1021 else
1022 {
1023 d("Requesting elemhide selectors from AdblockEngine for " + url + " in " + this);
1024 List<String> selectors = provider
1025 .getEngine()
1026 .getElementHidingSelectors(url, domain, referrers);
1015 1027
1016 d("Finished requesting elemhide selectors, got " + selectors.size() + " in " + this); 1028 d("Finished requesting elemhide selectors, got " + selectors.size() + " in " + this);
1017 selectorsString = Utils.stringListToJsonArray(selectors); 1029 selectorsString = Utils.stringListToJsonArray(selectors);
1030 }
1018 } 1031 }
1019 } 1032 }
1020 finally 1033 finally
1021 { 1034 {
1022 if (isCancelled.get()) 1035 if (isCancelled.get())
1023 { 1036 {
1024 w("This thread is cancelled, exiting silently " + this); 1037 w("This thread is cancelled, exiting silently " + this);
1025 } 1038 }
1026 else 1039 else
1027 { 1040 {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 d("Start loading " + newUrl); 1125 d("Start loading " + newUrl);
1113 1126
1114 loading = true; 1127 loading = true;
1115 addDomListener = true; 1128 addDomListener = true;
1116 elementsHidden = false; 1129 elementsHidden = false;
1117 loadError = null; 1130 loadError = null;
1118 url = newUrl; 1131 url = newUrl;
1119 1132
1120 if (url != null) 1133 if (url != null)
1121 { 1134 {
1122 try
1123 {
1124 d("Waiting for adblock engine");
1125 provider.waitForReady();
1126
1127 domain = provider.getEngine().getFilterEngine().getHostFromURL(url);
1128 if (domain == null)
1129 {
1130 throw new RuntimeException("Failed to extract domain from " + url);
1131 }
1132
1133 d("Extracted domain " + domain + " from " + url);
1134 }
1135 catch (Throwable t)
1136 {
1137 e("Failed to extract domain from " + url, t);
1138 }
1139
1140 elemHideLatch = new CountDownLatch(1); 1135 elemHideLatch = new CountDownLatch(1);
1141 elemHideThread = new ElemHideThread(elemHideLatch); 1136 elemHideThread = new ElemHideThread(elemHideLatch);
1142 elemHideThread.setFinishedRunnable(elemHideThreadFinishedRunnable); 1137 elemHideThread.setFinishedRunnable(elemHideThreadFinishedRunnable);
1143 elemHideThread.start(); 1138 elemHideThread.start();
1144 } 1139 }
1145 else 1140 else
1146 { 1141 {
1147 elemHideLatch = null; 1142 elemHideLatch = null;
1148 } 1143 }
1149 } 1144 }
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 w("Busy with elemhide selectors, delayed disposing scheduled"); 1432 w("Busy with elemhide selectors, delayed disposing scheduled");
1438 elemHideThread.setFinishedRunnable(disposeRunnable); 1433 elemHideThread.setFinishedRunnable(disposeRunnable);
1439 } 1434 }
1440 else 1435 else
1441 { 1436 {
1442 disposeRunnable.run(); 1437 disposeRunnable.run();
1443 } 1438 }
1444 } 1439 }
1445 } 1440 }
1446 } 1441 }
OLDNEW
« no previous file with comments | « libadblockplus-android-webview/pom.xml ('k') | libadblockplus-android-webviewapp/AndroidManifest.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld