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; |
| 17 import android.text.TextUtils; |
16 | 18 |
17 import org.chromium.base.Callback; | 19 import org.chromium.base.Callback; |
18 import org.chromium.base.ThreadUtils; | 20 import org.chromium.base.ThreadUtils; |
19 import org.chromium.base.VisibleForTesting; | 21 import org.chromium.base.VisibleForTesting; |
20 import org.chromium.base.annotations.CalledByNative; | 22 import org.chromium.base.annotations.CalledByNative; |
21 import org.chromium.base.library_loader.LibraryLoader; | 23 import org.chromium.base.library_loader.LibraryLoader; |
22 import org.chromium.base.library_loader.ProcessInitException; | 24 import org.chromium.base.library_loader.ProcessInitException; |
23 import org.chromium.base.metrics.RecordHistogram; | 25 import org.chromium.base.metrics.RecordHistogram; |
24 import org.chromium.chrome.browser.childaccounts.ChildAccountService; | 26 import org.chromium.chrome.browser.childaccounts.ChildAccountService; |
25 import org.chromium.chrome.browser.firstrun.ForcedSigninProcessor; | 27 import org.chromium.chrome.browser.firstrun.ForcedSigninProcessor; |
(...skipping 12 matching lines...) Expand all Loading... |
38 public class SupervisedUserContentProvider extends WebRestrictionsContentProvide
r { | 40 public class SupervisedUserContentProvider extends WebRestrictionsContentProvide
r { |
39 private static final String SUPERVISED_USER_CONTENT_PROVIDER_ENABLED = | 41 private static final String SUPERVISED_USER_CONTENT_PROVIDER_ENABLED = |
40 "SupervisedUserContentProviderEnabled"; | 42 "SupervisedUserContentProviderEnabled"; |
41 private long mNativeSupervisedUserContentProvider; | 43 private long mNativeSupervisedUserContentProvider; |
42 private boolean mChromeAlreadyStarted; | 44 private boolean mChromeAlreadyStarted; |
43 private static Object sEnabledLock = new Object(); | 45 private static Object sEnabledLock = new Object(); |
44 private static Object sContentProviderLock = new Object(); | 46 private static Object sContentProviderLock = new Object(); |
45 | 47 |
46 private static final String TAG = "SupervisedUserContent"; | 48 private static final String TAG = "SupervisedUserContent"; |
47 | 49 |
| 50 private static final String ACCOUNTS_GOOGLE_COM = "accounts.google.com"; |
| 51 private static final String GOOGLE_PLAY_SERVICES_UI_PACKAGE = "com.google.an
droid.gms.ui"; |
| 52 |
48 // Three value "boolean" caching enabled state, null if not yet known. | 53 // Three value "boolean" caching enabled state, null if not yet known. |
49 private static Boolean sEnabled; | 54 private static Boolean sEnabled; |
50 | 55 |
51 @VisibleForTesting | 56 @VisibleForTesting |
52 void startForcedSigninProcessor(Context appContext, Runnable onComplete) { | 57 void startForcedSigninProcessor(Context appContext, Runnable onComplete) { |
53 ForcedSigninProcessor.start(appContext, onComplete); | 58 ForcedSigninProcessor.start(appContext, onComplete); |
54 } | 59 } |
55 | 60 |
56 @VisibleForTesting | 61 @VisibleForTesting |
57 void listenForChildAccountStatusChange(Callback<Boolean> callback) { | 62 void listenForChildAccountStatusChange(Callback<Boolean> callback) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 }; | 157 }; |
153 onQueryFinished(new WebRestrictionsResult(false, errorInt, errorStri
ng)); | 158 onQueryFinished(new WebRestrictionsResult(false, errorInt, errorStri
ng)); |
154 } | 159 } |
155 | 160 |
156 void onQueryFailedNoErrorData() { | 161 void onQueryFailedNoErrorData() { |
157 onQueryFinished(new WebRestrictionsResult(false, null, null)); | 162 onQueryFinished(new WebRestrictionsResult(false, null, null)); |
158 } | 163 } |
159 } | 164 } |
160 | 165 |
161 @Override | 166 @Override |
162 protected WebRestrictionsResult shouldProceed(final String url) { | 167 protected WebRestrictionsResult shouldProceed(String callingPackage, final S
tring url) { |
163 // This will be called on multiple threads (but never the UI thread), | 168 // 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. | 169 // 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. | 170 // 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 | 171 // 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 | 172 // reply object for each query, and passing this through the callback st
ructure. The reply |
168 // object also handles waiting for the reply. | 173 // object also handles waiting for the reply. |
169 long startTimeMs = SystemClock.elapsedRealtime(); | 174 long startTimeMs = SystemClock.elapsedRealtime(); |
170 final SupervisedUserQueryReply queryReply = new SupervisedUserQueryReply
(); | 175 if (requestIsWhitelisted(callingPackage, url)) { |
| 176 return new WebRestrictionsResult(true, null, null); |
| 177 } |
| 178 |
171 final long contentProvider = getSupervisedUserContentProvider(); | 179 final long contentProvider = getSupervisedUserContentProvider(); |
172 if (contentProvider == 0) { | 180 if (contentProvider == 0) { |
173 return new WebRestrictionsResult( | 181 return new WebRestrictionsResult( |
174 false, new int[] {FilteringBehaviorReason.NOT_SIGNED_IN}, nu
ll); | 182 false, new int[] {FilteringBehaviorReason.NOT_SIGNED_IN}, nu
ll); |
175 } | 183 } |
| 184 |
| 185 final SupervisedUserQueryReply queryReply = new SupervisedUserQueryReply
(); |
176 ThreadUtils.runOnUiThread(new Runnable() { | 186 ThreadUtils.runOnUiThread(new Runnable() { |
177 @Override | 187 @Override |
178 public void run() { | 188 public void run() { |
179 nativeShouldProceed(contentProvider, queryReply, url); | 189 nativeShouldProceed(contentProvider, queryReply, url); |
180 } | 190 } |
181 }); | 191 }); |
182 try { | 192 try { |
183 // This will block until an onQueryComplete call on a different thre
ad adds | 193 // This will block until an onQueryComplete call on a different thre
ad adds |
184 // something to the queue. | 194 // something to the queue. |
185 WebRestrictionsResult result = queryReply.getResult(); | 195 WebRestrictionsResult result = queryReply.getResult(); |
186 String histogramName = mChromeAlreadyStarted | 196 String histogramName = mChromeAlreadyStarted |
187 ? "SupervisedUserContentProvider.ChromeStartedRequestTime" | 197 ? "SupervisedUserContentProvider.ChromeStartedRequestTime" |
188 : "SupervisedUserContentProvider.ChromeNotStartedRequestTime
"; | 198 : "SupervisedUserContentProvider.ChromeNotStartedRequestTime
"; |
189 RecordHistogram.recordTimesHistogram(histogramName, | 199 RecordHistogram.recordTimesHistogram(histogramName, |
190 SystemClock.elapsedRealtime() - startTimeMs, TimeUnit.MILLIS
ECONDS); | 200 SystemClock.elapsedRealtime() - startTimeMs, TimeUnit.MILLIS
ECONDS); |
191 RecordHistogram.recordBooleanHistogram( | 201 RecordHistogram.recordBooleanHistogram( |
192 "SupervisedUserContentProvider.RequestTimedOut", result == n
ull); | 202 "SupervisedUserContentProvider.RequestTimedOut", result == n
ull); |
193 if (result == null) return new WebRestrictionsResult(false, null, nu
ll); | 203 if (result == null) return new WebRestrictionsResult(false, null, nu
ll); |
194 return result; | 204 return result; |
195 } catch (InterruptedException e) { | 205 } catch (InterruptedException e) { |
196 return new WebRestrictionsResult(false, null, null); | 206 return new WebRestrictionsResult(false, null, null); |
197 } | 207 } |
198 } | 208 } |
199 | 209 |
| 210 private boolean requestIsWhitelisted(String callingPackage, String url) { |
| 211 // Always allow Google Play Services to show the reauthentication page (
which is necessary |
| 212 // to fix account issues). |
| 213 return TextUtils.equals(callingPackage, GOOGLE_PLAY_SERVICES_UI_PACKAGE) |
| 214 && Uri.parse(url).getHost().equals(ACCOUNTS_GOOGLE_COM); |
| 215 } |
| 216 |
200 @Override | 217 @Override |
201 protected boolean canInsert() { | 218 protected boolean canInsert() { |
202 // Chrome always allows insertion requests. | 219 // Chrome always allows insertion requests. |
203 return true; | 220 return true; |
204 } | 221 } |
205 | 222 |
206 static class SupervisedUserInsertReply extends SupervisedUserReply<Boolean>
{ | 223 static class SupervisedUserInsertReply extends SupervisedUserReply<Boolean>
{ |
207 @CalledByNative("SupervisedUserInsertReply") | 224 @CalledByNative("SupervisedUserInsertReply") |
208 void onInsertRequestSendComplete(boolean result) { | 225 void onInsertRequestSendComplete(boolean result) { |
209 onQueryFinished(result); | 226 onQueryFinished(result); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 346 |
330 native void nativeShouldProceed(long nativeSupervisedUserContentProvider, | 347 native void nativeShouldProceed(long nativeSupervisedUserContentProvider, |
331 SupervisedUserQueryReply queryReply, String url); | 348 SupervisedUserQueryReply queryReply, String url); |
332 | 349 |
333 native void nativeRequestInsert(long nativeSupervisedUserContentProvider, | 350 native void nativeRequestInsert(long nativeSupervisedUserContentProvider, |
334 SupervisedUserInsertReply insertReply, String url); | 351 SupervisedUserInsertReply insertReply, String url); |
335 | 352 |
336 private native void nativeSetFilterForTesting(long nativeSupervisedUserConte
ntProvider); | 353 private native void nativeSetFilterForTesting(long nativeSupervisedUserConte
ntProvider); |
337 | 354 |
338 } | 355 } |
OLD | NEW |