| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.webkit; |
| 18 |
|
| 19 |
import android.annotation.Nullable; |
| 20 |
import android.compat.annotation.UnsupportedAppUsage; |
| 21 |
import android.os.Build; |
| 22 |
import android.webkit.CacheManager.CacheResult; |
| 23 |
|
| 24 |
import java.util.Iterator; |
| 25 |
import java.util.LinkedList; |
| 26 |
import java.util.Map; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
@Deprecated |
| 34 |
public final class UrlInterceptRegistry { |
| 35 |
|
| 36 |
private final static String LOGTAG = "intercept"; |
| 37 |
|
| 38 |
private static boolean mDisabled = false; |
| 39 |
|
| 40 |
private static LinkedList mHandlerList; |
| 41 |
|
| 42 |
private static synchronized LinkedList getHandlers() { |
| 43 |
if(mHandlerList == null) |
| 44 |
mHandlerList = new LinkedList<UrlInterceptHandler>(); |
| 45 |
return mHandlerList; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
@Deprecated |
| 58 |
@UnsupportedAppUsage |
| 59 |
public static synchronized void setUrlInterceptDisabled(boolean disabled) { |
| 60 |
mDisabled = disabled; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
@Deprecated |
| 73 |
public static synchronized boolean urlInterceptDisabled() { |
| 74 |
return mDisabled; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
@Deprecated |
| 89 |
@UnsupportedAppUsage |
| 90 |
public static synchronized boolean registerHandler( |
| 91 |
UrlInterceptHandler handler) { |
| 92 |
if (!getHandlers().contains(handler)) { |
| 93 |
getHandlers().addFirst(handler); |
| 94 |
return true; |
| 95 |
} else { |
| 96 |
return false; |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
@Deprecated |
| 111 |
@UnsupportedAppUsage |
| 112 |
public static synchronized boolean unregisterHandler( |
| 113 |
UrlInterceptHandler handler) { |
| 114 |
return getHandlers().remove(handler); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
@Deprecated |
| 128 |
@Nullable |
| 129 |
public static synchronized CacheResult getSurrogate( |
| 130 |
String url, Map<String, String> headers) { |
| 131 |
if (urlInterceptDisabled()) { |
| 132 |
return null; |
| 133 |
} |
| 134 |
Iterator iter = getHandlers().listIterator(); |
| 135 |
while (iter.hasNext()) { |
| 136 |
UrlInterceptHandler handler = (UrlInterceptHandler) iter.next(); |
| 137 |
CacheResult result = handler.service(url, headers); |
| 138 |
if (result != null) { |
| 139 |
return result; |
| 140 |
} |
| 141 |
} |
| 142 |
return null; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
@Deprecated |
| 157 |
@Nullable |
| 158 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 159 |
public static synchronized PluginData getPluginData( |
| 160 |
String url, Map<String, String> headers) { |
| 161 |
if (urlInterceptDisabled()) { |
| 162 |
return null; |
| 163 |
} |
| 164 |
Iterator iter = getHandlers().listIterator(); |
| 165 |
while (iter.hasNext()) { |
| 166 |
UrlInterceptHandler handler = (UrlInterceptHandler) iter.next(); |
| 167 |
PluginData data = handler.getPluginData(url, headers); |
| 168 |
if (data != null) { |
| 169 |
return data; |
| 170 |
} |
| 171 |
} |
| 172 |
return null; |
| 173 |
} |
| 174 |
} |