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