OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.superviseduser; | 5 package org.chromium.chrome.browser.superviseduser; |
6 | 6 |
7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.content.BroadcastReceiver; | 8 import android.content.BroadcastReceiver; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.Intent; | 10 import android.content.Intent; |
11 import android.content.IntentFilter; | 11 import android.content.IntentFilter; |
12 import android.net.Uri; | |
12 import android.os.Build; | 13 import android.os.Build; |
13 import android.os.Bundle; | 14 import android.os.Bundle; |
14 import android.os.SystemClock; | 15 import android.os.SystemClock; |
15 import android.os.UserManager; | 16 import android.os.UserManager; |
16 | 17 |
17 import org.chromium.base.Callback; | 18 import org.chromium.base.Callback; |
18 import org.chromium.base.ThreadUtils; | 19 import org.chromium.base.ThreadUtils; |
19 import org.chromium.base.VisibleForTesting; | 20 import org.chromium.base.VisibleForTesting; |
20 import org.chromium.base.annotations.CalledByNative; | 21 import org.chromium.base.annotations.CalledByNative; |
21 import org.chromium.base.library_loader.LibraryLoader; | 22 import org.chromium.base.library_loader.LibraryLoader; |
(...skipping 16 matching lines...) Expand all Loading... | |
38 public class SupervisedUserContentProvider extends WebRestrictionsContentProvide r { | 39 public class SupervisedUserContentProvider extends WebRestrictionsContentProvide r { |
39 private static final String SUPERVISED_USER_CONTENT_PROVIDER_ENABLED = | 40 private static final String SUPERVISED_USER_CONTENT_PROVIDER_ENABLED = |
40 "SupervisedUserContentProviderEnabled"; | 41 "SupervisedUserContentProviderEnabled"; |
41 private long mNativeSupervisedUserContentProvider; | 42 private long mNativeSupervisedUserContentProvider; |
42 private boolean mChromeAlreadyStarted; | 43 private boolean mChromeAlreadyStarted; |
43 private static Object sEnabledLock = new Object(); | 44 private static Object sEnabledLock = new Object(); |
44 private static Object sContentProviderLock = new Object(); | 45 private static Object sContentProviderLock = new Object(); |
45 | 46 |
46 private static final String TAG = "SupervisedUserContent"; | 47 private static final String TAG = "SupervisedUserContent"; |
47 | 48 |
49 private static final Object ACCOUNTS_GOOGLE_COM = "accounts.google.com"; | |
50 private static final Object GOOGLE_PLAY_SERVICES_UI_PACKAGE = "com.google.an droid.gms.ui"; | |
51 | |
48 // Three value "boolean" caching enabled state, null if not yet known. | 52 // Three value "boolean" caching enabled state, null if not yet known. |
49 private static Boolean sEnabled; | 53 private static Boolean sEnabled; |
50 | 54 |
51 @VisibleForTesting | 55 @VisibleForTesting |
52 void startForcedSigninProcessor(Context appContext, Runnable onComplete) { | 56 void startForcedSigninProcessor(Context appContext, Runnable onComplete) { |
53 ForcedSigninProcessor.start(appContext, onComplete); | 57 ForcedSigninProcessor.start(appContext, onComplete); |
54 } | 58 } |
55 | 59 |
56 @VisibleForTesting | 60 @VisibleForTesting |
57 void listenForChildAccountStatusChange(Callback<Boolean> callback) { | 61 void listenForChildAccountStatusChange(Callback<Boolean> callback) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 }; | 156 }; |
153 onQueryFinished(new WebRestrictionsResult(false, errorInt, errorStri ng)); | 157 onQueryFinished(new WebRestrictionsResult(false, errorInt, errorStri ng)); |
154 } | 158 } |
155 | 159 |
156 void onQueryFailedNoErrorData() { | 160 void onQueryFailedNoErrorData() { |
157 onQueryFinished(new WebRestrictionsResult(false, null, null)); | 161 onQueryFinished(new WebRestrictionsResult(false, null, null)); |
158 } | 162 } |
159 } | 163 } |
160 | 164 |
161 @Override | 165 @Override |
162 protected WebRestrictionsResult shouldProceed(final String url) { | 166 protected WebRestrictionsResult shouldProceed(String callingPackage, final S tring url) { |
163 // This will be called on multiple threads (but never the UI thread), | 167 // This will be called on multiple threads (but never the UI thread), |
164 // see http://developer.android.com/guide/components/processes-and-threa ds.html#ThreadSafe. | 168 // see http://developer.android.com/guide/components/processes-and-threa ds.html#ThreadSafe. |
165 // The reply comes back on a different thread (possibly the UI thread) s ome time later. | 169 // The reply comes back on a different thread (possibly the UI thread) s ome time later. |
166 // As such it needs to correctly match the replies to the calls. It does this by creating a | 170 // As such it needs to correctly match the replies to the calls. It does this by creating a |
167 // reply object for each query, and passing this through the callback st ructure. The reply | 171 // reply object for each query, and passing this through the callback st ructure. The reply |
168 // object also handles waiting for the reply. | 172 // object also handles waiting for the reply. |
169 long startTimeMs = SystemClock.elapsedRealtime(); | 173 long startTimeMs = SystemClock.elapsedRealtime(); |
170 final SupervisedUserQueryReply queryReply = new SupervisedUserQueryReply (); | 174 if (requestIsWhitelisted(callingPackage, url)) { |
175 return new WebRestrictionsResult(true, null, null); | |
176 } | |
177 | |
171 final long contentProvider = getSupervisedUserContentProvider(); | 178 final long contentProvider = getSupervisedUserContentProvider(); |
172 if (contentProvider == 0) { | 179 if (contentProvider == 0) { |
173 return new WebRestrictionsResult( | 180 return new WebRestrictionsResult( |
174 false, new int[] {FilteringBehaviorReason.NOT_SIGNED_IN}, nu ll); | 181 false, new int[] {FilteringBehaviorReason.NOT_SIGNED_IN}, nu ll); |
175 } | 182 } |
183 | |
184 final SupervisedUserQueryReply queryReply = new SupervisedUserQueryReply (); | |
176 ThreadUtils.runOnUiThread(new Runnable() { | 185 ThreadUtils.runOnUiThread(new Runnable() { |
177 @Override | 186 @Override |
178 public void run() { | 187 public void run() { |
179 nativeShouldProceed(contentProvider, queryReply, url); | 188 nativeShouldProceed(contentProvider, queryReply, url); |
180 } | 189 } |
181 }); | 190 }); |
182 try { | 191 try { |
183 // This will block until an onQueryComplete call on a different thre ad adds | 192 // This will block until an onQueryComplete call on a different thre ad adds |
184 // something to the queue. | 193 // something to the queue. |
185 WebRestrictionsResult result = queryReply.getResult(); | 194 WebRestrictionsResult result = queryReply.getResult(); |
186 String histogramName = mChromeAlreadyStarted | 195 String histogramName = mChromeAlreadyStarted |
187 ? "SupervisedUserContentProvider.ChromeStartedRequestTime" | 196 ? "SupervisedUserContentProvider.ChromeStartedRequestTime" |
188 : "SupervisedUserContentProvider.ChromeNotStartedRequestTime "; | 197 : "SupervisedUserContentProvider.ChromeNotStartedRequestTime "; |
189 RecordHistogram.recordTimesHistogram(histogramName, | 198 RecordHistogram.recordTimesHistogram(histogramName, |
190 SystemClock.elapsedRealtime() - startTimeMs, TimeUnit.MILLIS ECONDS); | 199 SystemClock.elapsedRealtime() - startTimeMs, TimeUnit.MILLIS ECONDS); |
191 RecordHistogram.recordBooleanHistogram( | 200 RecordHistogram.recordBooleanHistogram( |
192 "SupervisedUserContentProvider.RequestTimedOut", result == n ull); | 201 "SupervisedUserContentProvider.RequestTimedOut", result == n ull); |
193 if (result == null) return new WebRestrictionsResult(false, null, nu ll); | 202 if (result == null) return new WebRestrictionsResult(false, null, nu ll); |
194 return result; | 203 return result; |
195 } catch (InterruptedException e) { | 204 } catch (InterruptedException e) { |
196 return new WebRestrictionsResult(false, null, null); | 205 return new WebRestrictionsResult(false, null, null); |
197 } | 206 } |
198 } | 207 } |
199 | 208 |
209 private boolean requestIsWhitelisted(String callingPackage, String url) { | |
210 // Always allow Google Play Services to show the reauthentication page ( which is necessary | |
211 // to fix account issues). | |
212 return callingPackage != null && callingPackage.equals(GOOGLE_PLAY_SERVI CES_UI_PACKAGE) | |
dgn
2017/02/23 12:19:49
nit: TextUtils.equals() to avoid having to check f
Bernhard Bauer
2017/02/23 16:36:21
Good idea! Done.
| |
213 && Uri.parse(url).getHost().equals(ACCOUNTS_GOOGLE_COM); | |
214 } | |
215 | |
200 @Override | 216 @Override |
201 protected boolean canInsert() { | 217 protected boolean canInsert() { |
202 // Chrome always allows insertion requests. | 218 // Chrome always allows insertion requests. |
203 return true; | 219 return true; |
204 } | 220 } |
205 | 221 |
206 static class SupervisedUserInsertReply extends SupervisedUserReply<Boolean> { | 222 static class SupervisedUserInsertReply extends SupervisedUserReply<Boolean> { |
207 @CalledByNative("SupervisedUserInsertReply") | 223 @CalledByNative("SupervisedUserInsertReply") |
208 void onInsertRequestSendComplete(boolean result) { | 224 void onInsertRequestSendComplete(boolean result) { |
209 onQueryFinished(result); | 225 onQueryFinished(result); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 | 345 |
330 native void nativeShouldProceed(long nativeSupervisedUserContentProvider, | 346 native void nativeShouldProceed(long nativeSupervisedUserContentProvider, |
331 SupervisedUserQueryReply queryReply, String url); | 347 SupervisedUserQueryReply queryReply, String url); |
332 | 348 |
333 native void nativeRequestInsert(long nativeSupervisedUserContentProvider, | 349 native void nativeRequestInsert(long nativeSupervisedUserContentProvider, |
334 SupervisedUserInsertReply insertReply, String url); | 350 SupervisedUserInsertReply insertReply, String url); |
335 | 351 |
336 private native void nativeSetFilterForTesting(long nativeSupervisedUserConte ntProvider); | 352 private native void nativeSetFilterForTesting(long nativeSupervisedUserConte ntProvider); |
337 | 353 |
338 } | 354 } |
OLD | NEW |