blob: eeb28d73be8503e7925e8c15ef0330f60e2a3bfc [file] [log] [blame]
Jonathan Dixon74fc73f2013-10-18 16:51:53 -07001/*
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
17package android.webkit;
18
Nate Fischer3442c742017-09-08 17:02:00 -070019import android.annotation.Nullable;
Mathew Inwood42afea22018-08-16 19:18:28 +010020import android.annotation.UnsupportedAppUsage;
Jonathan Dixon74fc73f2013-10-18 16:51:53 -070021import android.webkit.CacheManager.CacheResult;
22import android.webkit.PluginData;
23import android.webkit.UrlInterceptHandler;
24
25import java.util.Iterator;
26import java.util.LinkedList;
27import 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
35public 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 *
Nate Fischer0a6140d2017-09-05 12:37:49 -070052 * @param disabled {@code true} to disable the cache
Jonathan Dixon74fc73f2013-10-18 16:51:53 -070053 *
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
Mathew Inwood42afea22018-08-16 19:18:28 +010059 @UnsupportedAppUsage
Jonathan Dixon74fc73f2013-10-18 16:51:53 -070060 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
Nate Fischer0a6140d2017-09-05 12:37:49 -070083 * @return {@code true} if the handler was not previously registered.
Jonathan Dixon74fc73f2013-10-18 16:51:53 -070084 *
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
Mathew Inwood42afea22018-08-16 19:18:28 +010090 @UnsupportedAppUsage
Jonathan Dixon74fc73f2013-10-18 16:51:53 -070091 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.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700105 * @return {@code true} if the handler was found and removed from the list.
Jonathan Dixon74fc73f2013-10-18 16:51:53 -0700106 *
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
Mathew Inwood42afea22018-08-16 19:18:28 +0100112 @UnsupportedAppUsage
Jonathan Dixon74fc73f2013-10-18 16:51:53 -0700113 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
Nate Fischer0a6140d2017-09-05 12:37:49 -0700120 * UrlInterceptHandler interested, or {@code null} if none are.
Jonathan Dixon74fc73f2013-10-18 16:51:53 -0700121 *
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
Nate Fischer3442c742017-09-08 17:02:00 -0700129 @Nullable
Jonathan Dixon74fc73f2013-10-18 16:51:53 -0700130 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
Nate Fischer0a6140d2017-09-05 12:37:49 -0700148 * UrlInterceptHandler interested, or {@code null} if none are or if
Jonathan Dixon74fc73f2013-10-18 16:51:53 -0700149 * 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
Nate Fischer3442c742017-09-08 17:02:00 -0700158 @Nullable
Mathew Inwood42afea22018-08-16 19:18:28 +0100159 @UnsupportedAppUsage
Jonathan Dixon74fc73f2013-10-18 16:51:53 -0700160 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}