blob: c9dee00942c37c47495f6888e4b9dec7bddf7ef4 [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;
Artur Satayevad9254c2019-12-10 17:47:54 +000020import android.compat.annotation.UnsupportedAppUsage;
Jonathan Dixon74fc73f2013-10-18 16:51:53 -070021import android.webkit.CacheManager.CacheResult;
Jonathan Dixon74fc73f2013-10-18 16:51:53 -070022
23import java.util.Iterator;
24import java.util.LinkedList;
25import 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
33public 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
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 *
Nate Fischer0a6140d2017-09-05 12:37:49 -070050 * @param disabled {@code true} to disable the cache
Jonathan Dixon74fc73f2013-10-18 16:51:53 -070051 *
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
Mathew Inwood62d83fb2018-08-16 19:09:48 +010057 @UnsupportedAppUsage
Jonathan Dixon74fc73f2013-10-18 16:51:53 -070058 public static synchronized void setUrlInterceptDisabled(boolean disabled) {
59 mDisabled = disabled;
60 }
61
62 /**
63 * get the state of the url intercept, enabled or disabled
64 *
65 * @return return if it is disabled
66 *
67 * @hide
68 * @deprecated This class was intended to be used by Gears. Since Gears was
69 * deprecated, so is this class.
70 */
71 @Deprecated
72 public static synchronized boolean urlInterceptDisabled() {
73 return mDisabled;
74 }
75
76 /**
77 * Register a new UrlInterceptHandler. This handler will be called
78 * before any that were previously registered.
79 *
80 * @param handler The new UrlInterceptHandler object
Nate Fischer0a6140d2017-09-05 12:37:49 -070081 * @return {@code true} if the handler was not previously registered.
Jonathan Dixon74fc73f2013-10-18 16:51:53 -070082 *
83 * @hide
84 * @deprecated This class was intended to be used by Gears. Since Gears was
85 * deprecated, so is this class.
86 */
87 @Deprecated
Mathew Inwood62d83fb2018-08-16 19:09:48 +010088 @UnsupportedAppUsage
Jonathan Dixon74fc73f2013-10-18 16:51:53 -070089 public static synchronized boolean registerHandler(
90 UrlInterceptHandler handler) {
91 if (!getHandlers().contains(handler)) {
92 getHandlers().addFirst(handler);
93 return true;
94 } else {
95 return false;
96 }
97 }
98
99 /**
100 * Unregister a previously registered UrlInterceptHandler.
101 *
102 * @param handler A previously registered UrlInterceptHandler.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700103 * @return {@code true} if the handler was found and removed from the list.
Jonathan Dixon74fc73f2013-10-18 16:51:53 -0700104 *
105 * @hide
106 * @deprecated This class was intended to be used by Gears. Since Gears was
107 * deprecated, so is this class.
108 */
109 @Deprecated
Mathew Inwood62d83fb2018-08-16 19:09:48 +0100110 @UnsupportedAppUsage
Jonathan Dixon74fc73f2013-10-18 16:51:53 -0700111 public static synchronized boolean unregisterHandler(
112 UrlInterceptHandler handler) {
113 return getHandlers().remove(handler);
114 }
115
116 /**
117 * Given an url, returns the CacheResult of the first
Nate Fischer0a6140d2017-09-05 12:37:49 -0700118 * UrlInterceptHandler interested, or {@code null} if none are.
Jonathan Dixon74fc73f2013-10-18 16:51:53 -0700119 *
120 * @return A CacheResult containing surrogate content.
121 *
122 * @hide
123 * @deprecated This class was intended to be used by Gears. Since Gears was
124 * deprecated, so is this class.
125 */
126 @Deprecated
Nate Fischer3442c742017-09-08 17:02:00 -0700127 @Nullable
Jonathan Dixon74fc73f2013-10-18 16:51:53 -0700128 public static synchronized CacheResult getSurrogate(
129 String url, Map<String, String> headers) {
130 if (urlInterceptDisabled()) {
131 return null;
132 }
133 Iterator iter = getHandlers().listIterator();
134 while (iter.hasNext()) {
135 UrlInterceptHandler handler = (UrlInterceptHandler) iter.next();
136 CacheResult result = handler.service(url, headers);
137 if (result != null) {
138 return result;
139 }
140 }
141 return null;
142 }
143
144 /**
145 * Given an url, returns the PluginData of the first
Nate Fischer0a6140d2017-09-05 12:37:49 -0700146 * UrlInterceptHandler interested, or {@code null} if none are or if
Jonathan Dixon74fc73f2013-10-18 16:51:53 -0700147 * intercepts are disabled.
148 *
149 * @return A PluginData instance containing surrogate content.
150 *
151 * @hide
152 * @deprecated This class was intended to be used by Gears. Since Gears was
153 * deprecated, so is this class.
154 */
155 @Deprecated
Nate Fischer3442c742017-09-08 17:02:00 -0700156 @Nullable
Mathew Inwood62d83fb2018-08-16 19:09:48 +0100157 @UnsupportedAppUsage
Jonathan Dixon74fc73f2013-10-18 16:51:53 -0700158 public static synchronized PluginData getPluginData(
159 String url, Map<String, String> headers) {
160 if (urlInterceptDisabled()) {
161 return null;
162 }
163 Iterator iter = getHandlers().listIterator();
164 while (iter.hasNext()) {
165 UrlInterceptHandler handler = (UrlInterceptHandler) iter.next();
166 PluginData data = handler.getPluginData(url, headers);
167 if (data != null) {
168 return data;
169 }
170 }
171 return null;
172 }
173}