2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android.webkit;
19 import android.webkit.CacheManager.CacheResult;
20 import android.webkit.PluginData;
21 import android.webkit.UrlInterceptHandler;
23 import java.util.Iterator;
24 import java.util.LinkedList;
28 * @deprecated This class was intended to be used by Gears. Since Gears was
29 * deprecated, so is this class.
32 public final class UrlInterceptRegistry {
34 private final static String LOGTAG = "intercept";
36 private static boolean mDisabled = false;
38 private static LinkedList mHandlerList;
40 private static synchronized LinkedList getHandlers() {
41 if(mHandlerList == null)
42 mHandlerList = new LinkedList<UrlInterceptHandler>();
47 * set the flag to control whether url intercept is enabled or disabled
49 * @param disabled true to disable the cache
51 * @deprecated This class was intended to be used by Gears. Since Gears was
52 * deprecated, so is this class.
55 public static synchronized void setUrlInterceptDisabled(boolean disabled) {
60 * get the state of the url intercept, enabled or disabled
62 * @return return if it is disabled
64 * @deprecated This class was intended to be used by Gears. Since Gears was
65 * deprecated, so is this class.
68 public static synchronized boolean urlInterceptDisabled() {
73 * Register a new UrlInterceptHandler. This handler will be called
74 * before any that were previously registered.
76 * @param handler The new UrlInterceptHandler object
77 * @return true if the handler was not previously registered.
79 * @deprecated This class was intended to be used by Gears. Since Gears was
80 * deprecated, so is this class.
83 public static synchronized boolean registerHandler(
84 UrlInterceptHandler handler) {
85 if (!getHandlers().contains(handler)) {
86 getHandlers().addFirst(handler);
94 * Unregister a previously registered UrlInterceptHandler.
96 * @param handler A previously registered UrlInterceptHandler.
97 * @return true if the handler was found and removed from the list.
99 * @deprecated This class was intended to be used by Gears. Since Gears was
100 * deprecated, so is this class.
103 public static synchronized boolean unregisterHandler(
104 UrlInterceptHandler handler) {
105 return getHandlers().remove(handler);
109 * Given an url, returns the CacheResult of the first
110 * UrlInterceptHandler interested, or null if none are.
112 * @return A CacheResult containing surrogate content.
114 * @deprecated This class was intended to be used by Gears. Since Gears was
115 * deprecated, so is this class.
118 public static synchronized CacheResult getSurrogate(
119 String url, Map<String, String> headers) {
120 if (urlInterceptDisabled()) {
123 Iterator iter = getHandlers().listIterator();
124 while (iter.hasNext()) {
125 UrlInterceptHandler handler = (UrlInterceptHandler) iter.next();
126 CacheResult result = handler.service(url, headers);
127 if (result != null) {
135 * Given an url, returns the PluginData of the first
136 * UrlInterceptHandler interested, or null if none are or if
137 * intercepts are disabled.
139 * @return A PluginData instance containing surrogate content.
141 * @deprecated This class was intended to be used by Gears. Since Gears was
142 * deprecated, so is this class.
145 public static synchronized PluginData getPluginData(
146 String url, Map<String, String> headers) {
147 if (urlInterceptDisabled()) {
150 Iterator iter = getHandlers().listIterator();
151 while (iter.hasNext()) {
152 UrlInterceptHandler handler = (UrlInterceptHandler) iter.next();
153 PluginData data = handler.getPluginData(url, headers);