1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 package android.webkit;
18 
19 import android.webkit.CacheManager.CacheResult;
20 import android.webkit.PluginData;
21 import android.webkit.UrlInterceptHandler;
22 
23 import java.util.Iterator;
24 import java.util.LinkedList;
25 import java.util.Map;
26 
27 /**
28  * @hide
29  * @deprecated This class was intended to be used by Gears. Since Gears was
30  * deprecated, so is this class.
31  */
32 @Deprecated
33 public final class UrlInterceptRegistry {
34 
35     private final static String LOGTAG = "intercept";
36 
37     private static boolean mDisabled = false;
38 
39     private static LinkedList mHandlerList;
40 
getHandlers()41     private static synchronized LinkedList getHandlers() {
42         if(mHandlerList == null)
43             mHandlerList = new LinkedList<UrlInterceptHandler>();
44         return mHandlerList;
45     }
46 
47     /**
48      * set the flag to control whether url intercept is enabled or disabled
49      *
50      * @param disabled true to disable the cache
51      *
52      * @hide
53      * @deprecated This class was intended to be used by Gears. Since Gears was
54      * deprecated, so is this class.
55      */
56     @Deprecated
setUrlInterceptDisabled(boolean disabled)57     public static synchronized void setUrlInterceptDisabled(boolean disabled) {
58         mDisabled = disabled;
59     }
60 
61     /**
62      * get the state of the url intercept, enabled or disabled
63      *
64      * @return return if it is disabled
65      *
66      * @hide
67      * @deprecated This class was intended to be used by Gears. Since Gears was
68      * deprecated, so is this class.
69      */
70     @Deprecated
urlInterceptDisabled()71     public static synchronized boolean urlInterceptDisabled() {
72         return mDisabled;
73     }
74 
75     /**
76      * Register a new UrlInterceptHandler. This handler will be called
77      * before any that were previously registered.
78      *
79      * @param handler The new UrlInterceptHandler object
80      * @return true if the handler was not previously registered.
81      *
82      * @hide
83      * @deprecated This class was intended to be used by Gears. Since Gears was
84      * deprecated, so is this class.
85      */
86     @Deprecated
registerHandler( UrlInterceptHandler handler)87     public static synchronized boolean registerHandler(
88             UrlInterceptHandler handler) {
89         if (!getHandlers().contains(handler)) {
90             getHandlers().addFirst(handler);
91             return true;
92         } else {
93             return false;
94         }
95     }
96 
97     /**
98      * Unregister a previously registered UrlInterceptHandler.
99      *
100      * @param handler A previously registered UrlInterceptHandler.
101      * @return true if the handler was found and removed from the list.
102      *
103      * @hide
104      * @deprecated This class was intended to be used by Gears. Since Gears was
105      * deprecated, so is this class.
106      */
107     @Deprecated
unregisterHandler( UrlInterceptHandler handler)108     public static synchronized boolean unregisterHandler(
109             UrlInterceptHandler handler) {
110         return getHandlers().remove(handler);
111     }
112 
113     /**
114      * Given an url, returns the CacheResult of the first
115      * UrlInterceptHandler interested, or null if none are.
116      *
117      * @return A CacheResult containing surrogate content.
118      *
119      * @hide
120      * @deprecated This class was intended to be used by Gears. Since Gears was
121      * deprecated, so is this class.
122      */
123     @Deprecated
getSurrogate( String url, Map<String, String> headers)124     public static synchronized CacheResult getSurrogate(
125             String url, Map<String, String> headers) {
126         if (urlInterceptDisabled()) {
127             return null;
128         }
129         Iterator iter = getHandlers().listIterator();
130         while (iter.hasNext()) {
131             UrlInterceptHandler handler = (UrlInterceptHandler) iter.next();
132             CacheResult result = handler.service(url, headers);
133             if (result != null) {
134                 return result;
135             }
136         }
137         return null;
138     }
139 
140     /**
141      * Given an url, returns the PluginData of the first
142      * UrlInterceptHandler interested, or null if none are or if
143      * intercepts are disabled.
144      *
145      * @return A PluginData instance containing surrogate content.
146      *
147      * @hide
148      * @deprecated This class was intended to be used by Gears. Since Gears was
149      * deprecated, so is this class.
150      */
151     @Deprecated
getPluginData( String url, Map<String, String> headers)152     public static synchronized PluginData getPluginData(
153             String url, Map<String, String> headers) {
154         if (urlInterceptDisabled()) {
155             return null;
156         }
157         Iterator iter = getHandlers().listIterator();
158         while (iter.hasNext()) {
159             UrlInterceptHandler handler = (UrlInterceptHandler) iter.next();
160             PluginData data = handler.getPluginData(url, headers);
161             if (data != null) {
162                 return data;
163             }
164         }
165         return null;
166     }
167 }
168