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-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 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
811 else | 811 else |
812 { | 812 { |
813 super.onReceivedLoginRequest(view, realm, account, args); | 813 super.onReceivedLoginRequest(view, realm, account, args); |
814 } | 814 } |
815 } | 815 } |
816 | 816 |
817 protected WebResourceResponse shouldInterceptRequest( | 817 protected WebResourceResponse shouldInterceptRequest( |
818 WebView webview, String url, boolean isMainFrame, | 818 WebView webview, String url, boolean isMainFrame, |
819 boolean isXmlHttpRequest, String[] referrerChainArray) | 819 boolean isXmlHttpRequest, String[] referrerChainArray) |
820 { | 820 { |
821 // if dispose() was invoke, but the page is still loading then just let it go | 821 synchronized (provider.getEngineLock()) |
822 if (provider.getCounter() == 0) | |
823 { | 822 { |
824 e("FilterEngine already disposed, allow loading"); | 823 // if dispose() was invoke, but the page is still loading then just let it go |
diegocarloslima
2018/02/07 14:00:06
Not really related to the issue, but it seems that
anton
2018/02/07 14:03:22
Yes, it should be `invoked`.
Not fixing now as it'
| |
824 if (provider.getCounter() == 0) | |
825 { | |
826 e("FilterEngine already disposed, allow loading"); | |
825 | 827 |
826 // allow loading by returning null | 828 // allow loading by returning null |
827 return null; | 829 return null; |
828 } | |
829 else | |
830 { | |
831 provider.waitForReady(); | |
832 } | |
833 | |
834 if (isMainFrame) | |
835 { | |
836 // never blocking main frame requests, just subrequests | |
837 w(url + " is main frame, allow loading"); | |
838 | |
839 // allow loading by returning null | |
840 return null; | |
841 } | |
842 | |
843 // whitelisted | |
844 if (provider.getEngine().isDomainWhitelisted(url, referrerChainArray)) | |
845 { | |
846 w(url + " domain is whitelisted, allow loading"); | |
847 | |
848 // allow loading by returning null | |
849 return null; | |
850 } | |
851 | |
852 if (provider.getEngine().isDocumentWhitelisted(url, referrerChainArray)) | |
853 { | |
854 w(url + " document is whitelisted, allow loading"); | |
855 | |
856 // allow loading by returning null | |
857 return null; | |
858 } | |
859 | |
860 // determine the content | |
861 FilterEngine.ContentType contentType; | |
862 if (isXmlHttpRequest) | |
863 { | |
864 contentType = FilterEngine.ContentType.XMLHTTPREQUEST; | |
865 } | |
866 else | |
867 { | |
868 if (RE_JS.matcher(url).find()) | |
869 { | |
870 contentType = FilterEngine.ContentType.SCRIPT; | |
871 } | |
872 else if (RE_CSS.matcher(url).find()) | |
873 { | |
874 contentType = FilterEngine.ContentType.STYLESHEET; | |
875 } | |
876 else if (RE_IMAGE.matcher(url).find()) | |
877 { | |
878 contentType = FilterEngine.ContentType.IMAGE; | |
879 } | |
880 else if (RE_FONT.matcher(url).find()) | |
881 { | |
882 contentType = FilterEngine.ContentType.FONT; | |
883 } | |
884 else if (RE_HTML.matcher(url).find()) | |
885 { | |
886 contentType = FilterEngine.ContentType.SUBDOCUMENT; | |
887 } | 830 } |
888 else | 831 else |
889 { | 832 { |
890 contentType = FilterEngine.ContentType.OTHER; | 833 provider.waitForReady(); |
891 } | 834 } |
835 | |
836 if (isMainFrame) | |
837 { | |
838 // never blocking main frame requests, just subrequests | |
839 w(url + " is main frame, allow loading"); | |
840 | |
841 // allow loading by returning null | |
842 return null; | |
843 } | |
844 | |
845 // whitelisted | |
846 if (provider.getEngine().isDomainWhitelisted(url, referrerChainArray)) | |
847 { | |
848 w(url + " domain is whitelisted, allow loading"); | |
849 | |
850 // allow loading by returning null | |
851 return null; | |
852 } | |
853 | |
854 if (provider.getEngine().isDocumentWhitelisted(url, referrerChainArray)) | |
855 { | |
856 w(url + " document is whitelisted, allow loading"); | |
857 | |
858 // allow loading by returning null | |
859 return null; | |
860 } | |
861 | |
862 // determine the content | |
863 FilterEngine.ContentType contentType; | |
864 if (isXmlHttpRequest) | |
865 { | |
866 contentType = FilterEngine.ContentType.XMLHTTPREQUEST; | |
867 } | |
868 else | |
869 { | |
870 if (RE_JS.matcher(url).find()) | |
871 { | |
872 contentType = FilterEngine.ContentType.SCRIPT; | |
873 } | |
874 else if (RE_CSS.matcher(url).find()) | |
875 { | |
876 contentType = FilterEngine.ContentType.STYLESHEET; | |
877 } | |
878 else if (RE_IMAGE.matcher(url).find()) | |
879 { | |
880 contentType = FilterEngine.ContentType.IMAGE; | |
881 } | |
882 else if (RE_FONT.matcher(url).find()) | |
883 { | |
884 contentType = FilterEngine.ContentType.FONT; | |
885 } | |
886 else if (RE_HTML.matcher(url).find()) | |
887 { | |
888 contentType = FilterEngine.ContentType.SUBDOCUMENT; | |
889 } | |
890 else | |
891 { | |
892 contentType = FilterEngine.ContentType.OTHER; | |
893 } | |
894 } | |
895 | |
896 // check if we should block | |
897 if (provider.getEngine().matches(url, contentType, referrerChainArray)) | |
898 { | |
899 w("Blocked loading " + url); | |
900 | |
901 // if we should block, return empty response which results in 'errorLo ading' callback | |
902 return new WebResourceResponse("text/plain", "UTF-8", null); | |
903 } | |
904 | |
905 d("Allowed loading " + url); | |
906 | |
907 // continue by returning null | |
908 return null; | |
892 } | 909 } |
893 | |
894 // check if we should block | |
895 if (provider.getEngine().matches(url, contentType, referrerChainArray)) | |
896 { | |
897 w("Blocked loading " + url); | |
898 | |
899 // if we should block, return empty response which results in 'errorLoad ing' callback | |
900 return new WebResourceResponse("text/plain", "UTF-8", null); | |
901 } | |
902 | |
903 d("Allowed loading " + url); | |
904 | |
905 // continue by returning null | |
906 return null; | |
907 } | 910 } |
908 | 911 |
909 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 912 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
910 @Override | 913 @Override |
911 public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceR equest request) | 914 public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceR equest request) |
912 { | 915 { |
913 // here we just trying to fill url -> referrer map | 916 // here we just trying to fill url -> referrer map |
914 // blocking/allowing loading will happen in `shouldInterceptRequest(WebVie w,String)` | 917 // blocking/allowing loading will happen in `shouldInterceptRequest(WebVie w,String)` |
915 String url = request.getUrl().toString(); | 918 String url = request.getUrl().toString(); |
916 | 919 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
964 public ElemHideThread(CountDownLatch finishedLatch) | 967 public ElemHideThread(CountDownLatch finishedLatch) |
965 { | 968 { |
966 this.finishedLatch = finishedLatch; | 969 this.finishedLatch = finishedLatch; |
967 isFinished = new AtomicBoolean(false); | 970 isFinished = new AtomicBoolean(false); |
968 isCancelled = new AtomicBoolean(false); | 971 isCancelled = new AtomicBoolean(false); |
969 } | 972 } |
970 | 973 |
971 @Override | 974 @Override |
972 public void run() | 975 public void run() |
973 { | 976 { |
974 try | 977 synchronized (provider.getEngineLock()) |
975 { | 978 { |
976 if (provider.getCounter() == 0) | 979 try |
977 { | 980 { |
978 w("FilterEngine already disposed"); | 981 if (provider.getCounter() == 0) |
979 selectorsString = EMPTY_ELEMHIDE_ARRAY_STRING; | |
980 } | |
981 else | |
982 { | |
983 provider.waitForReady(); | |
984 String[] referrers = new String[] | |
985 { | |
986 url | |
987 }; | |
988 | |
989 List<Subscription> subscriptions = provider | |
990 .getEngine() | |
991 .getFilterEngine() | |
992 .getListedSubscriptions(); | |
993 | |
994 try | |
995 { | 982 { |
996 d("Listed subscriptions: " + subscriptions.size()); | 983 w("FilterEngine already disposed"); |
997 if (debugMode) | |
998 { | |
999 for (Subscription eachSubscription : subscriptions) | |
1000 { | |
1001 d("Subscribed to " | |
1002 + (eachSubscription.isDisabled() ? "disabled" : "enabled") | |
1003 + " " + eachSubscription); | |
1004 } | |
1005 } | |
1006 } | |
1007 finally | |
1008 { | |
1009 for (Subscription eachSubscription : subscriptions) | |
1010 { | |
1011 eachSubscription.dispose(); | |
1012 } | |
1013 } | |
1014 | |
1015 final String domain = provider.getEngine().getFilterEngine().getHostFr omURL(url); | |
1016 if (domain == null) | |
1017 { | |
1018 e("Failed to extract domain from " + url); | |
1019 selectorsString = EMPTY_ELEMHIDE_ARRAY_STRING; | 984 selectorsString = EMPTY_ELEMHIDE_ARRAY_STRING; |
1020 } | 985 } |
1021 else | 986 else |
1022 { | 987 { |
1023 d("Requesting elemhide selectors from AdblockEngine for " + url + " in " + this); | 988 provider.waitForReady(); |
1024 List<String> selectors = provider | 989 String[] referrers = new String[] |
990 { | |
991 url | |
992 }; | |
993 | |
994 List<Subscription> subscriptions = provider | |
1025 .getEngine() | 995 .getEngine() |
1026 .getElementHidingSelectors(url, domain, referrers); | 996 .getFilterEngine() |
997 .getListedSubscriptions(); | |
1027 | 998 |
1028 d("Finished requesting elemhide selectors, got " + selectors.size() + " in " + this); | 999 try |
1029 selectorsString = Utils.stringListToJsonArray(selectors); | 1000 { |
1001 d("Listed subscriptions: " + subscriptions.size()); | |
1002 if (debugMode) | |
1003 { | |
1004 for (Subscription eachSubscription : subscriptions) | |
1005 { | |
1006 d("Subscribed to " | |
1007 + (eachSubscription.isDisabled() ? "disabled" : "enabled") | |
1008 + " " + eachSubscription); | |
1009 } | |
1010 } | |
1011 } | |
1012 finally | |
1013 { | |
1014 for (Subscription eachSubscription : subscriptions) | |
1015 { | |
1016 eachSubscription.dispose(); | |
1017 } | |
1018 } | |
1019 | |
1020 final String domain = provider.getEngine().getFilterEngine().getHost FromURL(url); | |
1021 if (domain == null) | |
1022 { | |
1023 e("Failed to extract domain from " + url); | |
1024 selectorsString = EMPTY_ELEMHIDE_ARRAY_STRING; | |
1025 } | |
1026 else | |
1027 { | |
1028 d("Requesting elemhide selectors from AdblockEngine for " + url + " in " + this); | |
1029 List<String> selectors = provider | |
1030 .getEngine() | |
1031 .getElementHidingSelectors(url, domain, referrers); | |
1032 | |
1033 d("Finished requesting elemhide selectors, got " + selectors.size( ) + " in " + this); | |
1034 selectorsString = Utils.stringListToJsonArray(selectors); | |
1035 } | |
1030 } | 1036 } |
1031 } | 1037 } |
1032 } | 1038 finally |
1033 finally | |
1034 { | |
1035 if (isCancelled.get()) | |
1036 { | 1039 { |
1037 w("This thread is cancelled, exiting silently " + this); | 1040 if (isCancelled.get()) |
1038 } | 1041 { |
1039 else | 1042 w("This thread is cancelled, exiting silently " + this); |
1040 { | 1043 } |
1041 finish(selectorsString); | 1044 else |
1045 { | |
1046 finish(selectorsString); | |
1047 } | |
1042 } | 1048 } |
1043 } | 1049 } |
1044 } | 1050 } |
1045 | 1051 |
1046 private void onFinished() | 1052 private void onFinished() |
1047 { | 1053 { |
1048 finishedLatch.countDown(); | 1054 finishedLatch.countDown(); |
1049 synchronized (finishedRunnableLockObject) | 1055 synchronized (finishedRunnableLockObject) |
1050 { | 1056 { |
1051 if (finishedRunnable != null) | 1057 if (finishedRunnable != null) |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1432 w("Busy with elemhide selectors, delayed disposing scheduled"); | 1438 w("Busy with elemhide selectors, delayed disposing scheduled"); |
1433 elemHideThread.setFinishedRunnable(disposeRunnable); | 1439 elemHideThread.setFinishedRunnable(disposeRunnable); |
1434 } | 1440 } |
1435 else | 1441 else |
1436 { | 1442 { |
1437 disposeRunnable.run(); | 1443 disposeRunnable.run(); |
1438 } | 1444 } |
1439 } | 1445 } |
1440 } | 1446 } |
1441 } | 1447 } |
OLD | NEW |