summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjam <jam@chromium.org>2015-12-17 12:10:03 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-17 20:11:03 +0000
commit2187ddb9a33c00b8af78ab7b4562af90109fe1f8 (patch)
tree08e508c8af4c02ed76393bb7efe0c3b803266eb1 /chrome
parenteef43622fa091ff4b95649c4df5f840c4ee0f44b (diff)
downloadchromium_src-2187ddb9a33c00b8af78ab7b4562af90109fe1f8.zip
chromium_src-2187ddb9a33c00b8af78ab7b4562af90109fe1f8.tar.gz
chromium_src-2187ddb9a33c00b8af78ab7b4562af90109fe1f8.tar.bz2
Revert of Supervised user web restrictions content provider (patchset #12 id:220001 of https://codereview.chromium.org/1452603002/ )
Reason for revert: The new test is failing on CQ BUG=570768 Original issue's description: > Supervised user web restrictions content provider > > The web restrictions content provider lets other apps query > web restrictions. In particular it lets apps using WebView > query Chrome's supervised user web restrictions. > > BUG=569879 > > Committed: https://crrev.com/d501894251559fe547bda9381bdeb98d229f6e7c > Cr-Commit-Position: refs/heads/master@{#365834} TBR=jochen@chromium.org,bauerb@chromium.org,knn@chromium.org,aberent@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=569879 Review URL: https://codereview.chromium.org/1539653002 Cr-Commit-Position: refs/heads/master@{#365870}
Diffstat (limited to 'chrome')
-rw-r--r--chrome/android/BUILD.gn3
-rw-r--r--chrome/android/java/AndroidManifest.xml6
-rw-r--r--chrome/android/java/DEPS1
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java7
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProvider.java180
-rw-r--r--chrome/android/javatests/DEPS1
-rw-r--r--chrome/android/javatests/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderTest.java112
-rw-r--r--chrome/android/junit/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderUnitTest.java230
-rw-r--r--chrome/browser/android/chrome_jni_registrar.cc2
-rw-r--r--chrome/browser/android/preferences/pref_service_bridge.cc7
-rw-r--r--chrome/browser/supervised_user/supervised_user_content_provider_android.cc141
-rw-r--r--chrome/browser/supervised_user/supervised_user_content_provider_android.h55
-rw-r--r--chrome/browser/supervised_user/supervised_user_interstitial.cc30
-rw-r--r--chrome/browser/supervised_user/supervised_user_interstitial.h4
-rw-r--r--chrome/chrome.gyp1
-rw-r--r--chrome/chrome_browser.gypi3
16 files changed, 11 insertions, 772 deletions
diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn
index 7698bac..d880717 100644
--- a/chrome/android/BUILD.gn
+++ b/chrome/android/BUILD.gn
@@ -133,8 +133,6 @@ android_library("chrome_java") {
"//base:base_java",
"//components/safe_json/android:safe_json_java",
"//components/variations/android:variations_java",
- "//components/web_contents_delegate_android:web_contents_delegate_android_java",
- "//components/web_restriction:web_restriction_java",
"//content/public/android:content_java",
"//media/base/android:media_java",
"//media/midi:midi_java",
@@ -342,7 +340,6 @@ android_library("chrome_shared_test_java") {
"//components/precache/android:precache_java",
"//components/precache/android:precache_javatests",
"//components/web_contents_delegate_android:web_contents_delegate_android_java",
- "//components/web_restriction:web_restriction_java",
"//content/public/android:content_java",
"//content/public/test/android:content_java_test_support",
"//net/android:net_java",
diff --git a/chrome/android/java/AndroidManifest.xml b/chrome/android/java/AndroidManifest.xml
index 3b2cd4b..47cca4c 100644
--- a/chrome/android/java/AndroidManifest.xml
+++ b/chrome/android/java/AndroidManifest.xml
@@ -423,12 +423,6 @@ by a child template that "extends" this file.
android:resource="@xml/file_paths" />
</provider>
- <provider android:name="org.chromium.chrome.browser.superviseduser.SupervisedUserContentProvider"
- android:authorities="{{ manifest_package }}.SupervisedUserProvider"
- android:permission="android.permission.INTERNET"
- android:exported="true">
- </provider>
-
<!-- Sync adapter for browser invalidation. -->
<service android:name="org.chromium.chrome.browser.invalidation.ChromeBrowserSyncAdapterService"
android:exported="false">
diff --git a/chrome/android/java/DEPS b/chrome/android/java/DEPS
index 5c33936..acf1ccfa 100644
--- a/chrome/android/java/DEPS
+++ b/chrome/android/java/DEPS
@@ -7,7 +7,6 @@ include_rules = [
"+components/precache/android/java",
"+components/service_tab_launcher",
"+components/web_contents_delegate_android",
- "+components/web_restriction",
"+content/public/android/java",
"+sync/android/java/src/org/chromium/sync",
]
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java
index 40df783..1d6755a 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java
@@ -10,7 +10,6 @@ import android.preference.PreferenceManager;
import android.util.Log;
import org.chromium.base.ThreadUtils;
-import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.ContentSettingsType;
import org.chromium.chrome.browser.preferences.website.ContentSetting;
@@ -924,11 +923,6 @@ public final class PrefServiceBridge {
return nativeGetClickedUpdateMenuItem();
}
- @VisibleForTesting
- public void setSupervisedUserId(String supervisedUserId) {
- nativeSetSupervisedUserId(supervisedUserId);
- }
-
private native boolean nativeGetAcceptCookiesEnabled();
private native boolean nativeGetAcceptCookiesManaged();
private native boolean nativeGetBlockThirdPartyCookiesEnabled();
@@ -1023,5 +1017,4 @@ public final class PrefServiceBridge {
private native boolean nativeHasSetMetricsReporting();
private native void nativeSetClickedUpdateMenuItem(boolean clicked);
private native boolean nativeGetClickedUpdateMenuItem();
- private native void nativeSetSupervisedUserId(String supervisedUserId);
}
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProvider.java b/chrome/android/java/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProvider.java
deleted file mode 100644
index 3baf141..0000000
--- a/chrome/android/java/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProvider.java
+++ /dev/null
@@ -1,180 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package org.chromium.chrome.browser.superviseduser;
-
-import android.os.Bundle;
-import android.util.Pair;
-
-import org.chromium.base.ThreadUtils;
-import org.chromium.base.VisibleForTesting;
-import org.chromium.base.annotations.CalledByNative;
-import org.chromium.base.library_loader.LibraryProcessType;
-import org.chromium.base.library_loader.ProcessInitException;
-import org.chromium.components.webrestriction.WebRestrictionsContentProvider;
-import org.chromium.content.browser.BrowserStartupController;
-
-import java.util.concurrent.CountDownLatch;
-
-/**
- * Content provider for telling other apps (e.g. WebView apps) about the supervised user URL filter.
- */
-public class SupervisedUserContentProvider extends WebRestrictionsContentProvider {
- private long mNativeSupervisedUserContentProvider = 0;
-
- private long getSupervisedUserContentProvider() throws ProcessInitException {
- if (mNativeSupervisedUserContentProvider != 0) {
- return mNativeSupervisedUserContentProvider;
- }
-
- BrowserStartupController.get(getContext(), LibraryProcessType.PROCESS_BROWSER)
- .startBrowserProcessesSync(false);
-
- mNativeSupervisedUserContentProvider = nativeCreateSupervisedUserContentProvider();
- return mNativeSupervisedUserContentProvider;
- }
-
- @VisibleForTesting
- void setNativeSupervisedUserContentProviderForTesting(long nativeProvider) {
- mNativeSupervisedUserContentProvider = nativeProvider;
- }
-
- @VisibleForTesting
- static class SupervisedUserQueryReply {
- final CountDownLatch mLatch = new CountDownLatch(1);
- private Pair<Boolean, String> mResult;
- @VisibleForTesting
- @CalledByNative("SupervisedUserQueryReply")
- void onQueryComplete(boolean result, String errorMessage) {
- // This must be called precisely once per query.
- assert mResult == null;
- mResult = new Pair<Boolean, String>(result, errorMessage);
- mLatch.countDown();
- }
- Pair<Boolean, String> getResult() throws InterruptedException {
- mLatch.await();
- return mResult;
- }
- }
-
- @Override
- protected Pair<Boolean, String> shouldProceed(final String url) {
- // This will be called on multiple threads (but never the UI thread),
- // see http://developer.android.com/guide/components/processes-and-threads.html#ThreadSafe.
- // The reply comes back on a different thread (possibly the UI thread) some time later.
- // As such it needs to correctly match the replies to the calls. It does this by creating a
- // reply object for each query, and passing this through the callback structure. The reply
- // object also handles waiting for the reply.
- assert !ThreadUtils.runningOnUiThread();
- final SupervisedUserQueryReply queryReply = new SupervisedUserQueryReply();
- ThreadUtils.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- nativeShouldProceed(getSupervisedUserContentProvider(), queryReply, url);
- } catch (ProcessInitException e) {
- queryReply.onQueryComplete(false, null);
- }
- }
- });
- try {
- // This will block until an onQueryComplete call on a different thread adds
- // something to the queue.
- return queryReply.getResult();
- } catch (InterruptedException e) {
- return new Pair<Boolean, String>(false, null);
- }
- }
-
- @Override
- protected boolean canInsert() {
- // Chrome always allows insertion requests.
- return true;
- }
-
- @VisibleForTesting
- static class SupervisedUserInsertReply {
- final CountDownLatch mLatch = new CountDownLatch(1);
- boolean mResult;
- @VisibleForTesting
- @CalledByNative("SupervisedUserInsertReply")
- void onInsertRequestSendComplete(boolean result) {
- // This must be called precisely once per query.
- assert mLatch.getCount() == 1;
- mResult = result;
- mLatch.countDown();
- }
- boolean getResult() throws InterruptedException {
- mLatch.await();
- return mResult;
- }
- }
-
- @Override
- protected boolean requestInsert(final String url) {
- // This will be called on multiple threads (but never the UI thread),
- // see http://developer.android.com/guide/components/processes-and-threads.html#ThreadSafe.
- // The reply comes back on a different thread (possibly the UI thread) some time later.
- // As such it needs to correctly match the replies to the calls. It does this by creating a
- // reply object for each query, and passing this through the callback structure. The reply
- // object also handles waiting for the reply.
- assert !ThreadUtils.runningOnUiThread();
- final SupervisedUserInsertReply insertReply = new SupervisedUserInsertReply();
- ThreadUtils.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- nativeRequestInsert(getSupervisedUserContentProvider(), insertReply, url);
- } catch (ProcessInitException e) {
- insertReply.onInsertRequestSendComplete(false);
- }
- }
- });
- try {
- return insertReply.getResult();
- } catch (InterruptedException e) {
- return false;
- }
- }
-
- @VisibleForTesting
- @Override
- public Bundle call(String method, String arg, Bundle bundle) {
- if (method.equals("setFilterForTesting")) setFilterForTesting();
- return null;
- }
-
- @VisibleForTesting
- void setFilterForTesting() {
- ThreadUtils.runOnUiThreadBlocking(new Runnable() {
- @Override
- public void run() {
- try {
- nativeSetFilterForTesting(getSupervisedUserContentProvider());
- } catch (ProcessInitException e) {
- // There is no way of returning anything sensible here, so ignore the error and
- // do nothing.
- }
- }
- });
- }
-
- @VisibleForTesting
- @CalledByNative
- void onSupervisedUserFilterUpdated() {
- onFilterChanged();
- }
-
- @VisibleForTesting native long nativeCreateSupervisedUserContentProvider();
-
- @VisibleForTesting
- native void nativeShouldProceed(long nativeSupervisedUserContentProvider,
- SupervisedUserQueryReply queryReply, String url);
-
- @VisibleForTesting
- native void nativeRequestInsert(long nativeSupervisedUserContentProvider,
- SupervisedUserInsertReply insertReply, String url);
-
- private native void nativeSetFilterForTesting(long nativeSupervisedUserContentProvider);
-}
diff --git a/chrome/android/javatests/DEPS b/chrome/android/javatests/DEPS
index 51445be..6f2d48d 100644
--- a/chrome/android/javatests/DEPS
+++ b/chrome/android/javatests/DEPS
@@ -4,7 +4,6 @@ include_rules = [
"+components/gcm_driver/android/java/src/org/chromium/components/gcm_driver",
"+components/navigation_interception",
"+components/precache/android/javatests",
- "+components/web_restriction",
"+content/public/android/java",
"+sync/android/java/src/org/chromium/sync",
# We should only depend on the util package of something that lives in
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderTest.java
deleted file mode 100644
index 432f48f..0000000
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package org.chromium.chrome.browser.superviseduser;
-
-import android.accounts.Account;
-import android.content.ContentProviderClient;
-import android.content.ContentResolver;
-import android.database.Cursor;
-import android.net.Uri;
-import android.os.RemoteException;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import org.chromium.base.ThreadUtils;
-import org.chromium.chrome.browser.ChromeActivity;
-import org.chromium.chrome.browser.childaccounts.ChildAccountService;
-import org.chromium.chrome.browser.preferences.PrefServiceBridge;
-import org.chromium.chrome.test.ChromeActivityTestCaseBase;
-import org.chromium.chrome.test.util.browser.signin.SigninTestUtil;
-import org.chromium.components.webrestriction.WebRestrictionsContentProvider;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-
-/**
- * Instrumentation test for SupervisedUserContentProvider.
- */
-public class SupervisedUserContentProviderTest extends ChromeActivityTestCaseBase<ChromeActivity> {
- private static final String DEFAULT_ACCOUNT = "test@gmail.com";
- private static final String AUTHORITY_SUFFIX = ".SupervisedUserProvider";
- private ContentResolver mResolver;
- private String mAuthority;
- private Uri mUri;
-
- public SupervisedUserContentProviderTest() {
- super(ChromeActivity.class);
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- mResolver = getInstrumentation().getContext().getContentResolver();
- assertNotNull(mResolver);
- mAuthority = getInstrumentation().getTargetContext().getPackageName() + AUTHORITY_SUFFIX;
- mUri = new Uri.Builder()
- .scheme(ContentResolver.SCHEME_CONTENT)
- .authority(mAuthority)
- .path("authorized")
- .build();
- SigninTestUtil.get().resetSigninState();
- }
-
- @Override
- public void tearDown() throws Exception {
- SigninTestUtil.get().resetSigninState();
- super.tearDown();
- }
-
- @Override
- public void startMainActivity() throws InterruptedException {
- SigninTestUtil.setUpAuthForTest(getInstrumentation());
-
- // In principle the SupervisedUserContentProvider should work whenever Chrome is installed
- // (even if it isn't running), but to test it we need to set up a dummy child, and to do
- // this within a test we need to start Chrome.
- startMainActivityOnBlankPage();
- }
-
- @SmallTest
- public void testNoSupervisedUser() throws RemoteException, ExecutionException {
- assertFalse(ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() {
-
- @Override
- public Boolean call() throws Exception {
- PrefServiceBridge.getInstance().setSupervisedUserId("");
- return ChildAccountService.isChildAccount();
- }
-
- }));
- ContentProviderClient client = mResolver.acquireContentProviderClient(mAuthority);
- assertNotNull(client);
- Cursor cursor = client.query(mUri, null, "url = 'http://google.com'", null, null);
- assertNotNull(cursor);
- assertEquals(WebRestrictionsContentProvider.PROCEED, cursor.getInt(0));
- cursor = client.query(mUri, null, "url = 'http://www.notgoogle.com'", null, null);
- assertNotNull(cursor);
- assertEquals(WebRestrictionsContentProvider.PROCEED, cursor.getInt(0));
- }
-
- @SmallTest
- public void testWithSupervisedUser() throws RemoteException, ExecutionException {
- final Account account = SigninTestUtil.get().addAndSignInTestAccount();
- assertNotNull(account);
- assertTrue(ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() {
-
- @Override
- public Boolean call() throws Exception {
- PrefServiceBridge.getInstance().setSupervisedUserId("ChildAccountSUID");
- return ChildAccountService.isChildAccount();
- }
-
- }));
- ContentProviderClient client = mResolver.acquireContentProviderClient(mAuthority);
- assertNotNull(client);
- // setFilter for testing sets a default filter that blocks by default.
- mResolver.call(mUri, "setFilterForTesting", null, null);
- Cursor cursor = client.query(mUri, null, "url = 'http://www.google.com'", null, null);
- assertNotNull(cursor);
- assertEquals(WebRestrictionsContentProvider.BLOCKED, cursor.getInt(0));
- }
-}
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderUnitTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderUnitTest.java
deleted file mode 100644
index 1734826..0000000
--- a/chrome/android/junit/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderUnitTest.java
+++ /dev/null
@@ -1,230 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package org.chromium.chrome.browser.superviseduser;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-import android.os.Handler;
-import android.os.Looper;
-import android.util.Pair;
-
-import org.chromium.testing.local.LocalRobolectricTestRunner;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.robolectric.Robolectric;
-import org.robolectric.annotation.Config;
-import org.robolectric.annotation.Implementation;
-import org.robolectric.annotation.Implements;
-
-import java.util.concurrent.CountDownLatch;
-
-/**
- * Tests of SupervisedUserContentProvider. This is tested as a simple class, not as a content
- * provider. The content provider aspects are tested with WebRestrictionsContentProviderTest.
- */
-@RunWith(LocalRobolectricTestRunner.class)
-@Config(manifest = Config.NONE,
- shadows = {SupervisedUserContentProviderUnitTest.ShadowHander.class})
-public class SupervisedUserContentProviderUnitTest {
- private static CountDownLatch sLatch;
-
- /**
- * Special Handler shadow class that allows the test to wait for a post() call.
- */
- @Implements(Handler.class)
- public static class ShadowHander extends org.robolectric.shadows.ShadowHandler {
- @Override
- @Implementation
- public boolean post(Runnable r) {
- boolean result = super.post(r);
- // If the test wants to wait it should initialize sLatch before post is called.
- if (sLatch != null) sLatch.countDown();
- return result;
- }
- }
-
- private SupervisedUserContentProvider mSupervisedUserContentProvider;
- private Looper mNativeCallLooper;
-
- @Before
- public void setUp() {
- sLatch = null;
- mNativeCallLooper = null;
- mSupervisedUserContentProvider = Mockito.spy(new SupervisedUserContentProvider());
- mSupervisedUserContentProvider.setNativeSupervisedUserContentProviderForTesting(1234L);
- }
-
- @Test
- public void testShouldProceed() throws InterruptedException {
- // Runnable for test thread.
- class TestRunnable implements Runnable {
- private Pair<Boolean, String> mResult;
-
- @Override
- public void run() {
- this.mResult = mSupervisedUserContentProvider.shouldProceed("url");
- }
-
- public Pair<Boolean, String> getResult() {
- return mResult;
- }
- }
- // Mock the native call for a permitted URL
- doAnswer(new Answer<Void>() {
-
- @Override
- public Void answer(InvocationOnMock invocation) throws Throwable {
- Object args[] = invocation.getArguments();
- mNativeCallLooper = Looper.myLooper();
- ((SupervisedUserContentProvider.SupervisedUserQueryReply) args[1])
- .onQueryComplete(true, null);
- return null;
- }
-
- })
- .when(mSupervisedUserContentProvider)
- .nativeShouldProceed(anyLong(),
- any(SupervisedUserContentProvider.SupervisedUserQueryReply.class),
- anyString());
- TestRunnable r1 = new TestRunnable();
- // Because SupervisedUserContentProvider uses a CountDownLatch (which is a java.util
- // class, so can't be shadowed or mocked) we need to make the calls to shouldProceed on a
- // real thread. This can't be the main thread because Robolectric emulates UI event handling
- // on the main thread.
- Thread t1 = new Thread(r1);
- sLatch = new CountDownLatch(1);
- t1.start();
- // Wait for the event to be posted to the emulated UI thread.
- sLatch.await();
- Robolectric.runUiThreadTasks();
- t1.join();
- verify(mSupervisedUserContentProvider)
- .nativeShouldProceed(eq(1234L),
- any(SupervisedUserContentProvider.SupervisedUserQueryReply.class),
- eq("url"));
- // Assert has to be on main thread for failures to cause test failure.
- assertThat(r1.getResult(), is(new Pair<Boolean, String>(true, null)));
- // Check that the native code was called on the right thread.
- assertThat(mNativeCallLooper, is(Looper.getMainLooper()));
- // Mock the native call for a forbidden URL
- doAnswer(new Answer<Void>() {
-
- @Override
- public Void answer(InvocationOnMock invocation) throws Throwable {
- Object args[] = invocation.getArguments();
- mNativeCallLooper = Looper.myLooper();
- ((SupervisedUserContentProvider.SupervisedUserQueryReply) args[1])
- .onQueryComplete(false, "Hello");
- return null;
- }
-
- })
- .when(mSupervisedUserContentProvider)
- .nativeShouldProceed(anyLong(),
- any(SupervisedUserContentProvider.SupervisedUserQueryReply.class),
- anyString());
- TestRunnable r2 = new TestRunnable();
- // Create a new thread for the second call
- Thread t2 = new Thread(r2);
- sLatch = new CountDownLatch(1);
- t2.start();
- // Wait for the event to be posted to the emulated UI thread.
- sLatch.await();
- Robolectric.runUiThreadTasksIncludingDelayedTasks();
- t2.join();
- assertThat(r2.getResult(), is(new Pair<Boolean, String>(false, "Hello")));
- // Check that the native code was called on the UI thread.
- assertThat(mNativeCallLooper, is(Looper.getMainLooper()));
- }
-
- @Test
- public void testRequestInsert() throws InterruptedException {
- // Runnable for test thread.
- class TestRunnable implements Runnable {
- private boolean mResult;
-
- @Override
- public void run() {
- this.mResult = mSupervisedUserContentProvider.requestInsert("url");
- }
-
- public boolean getResult() {
- return mResult;
- }
- }
- // Mock native call.
- doAnswer(new Answer<Void>() {
-
- @Override
- public Void answer(InvocationOnMock invocation) throws Throwable {
- Object args[] = invocation.getArguments();
- mNativeCallLooper = Looper.myLooper();
- ((SupervisedUserContentProvider.SupervisedUserInsertReply) args[1])
- .onInsertRequestSendComplete(true);
- return null;
- }
-
- })
- .when(mSupervisedUserContentProvider)
- .nativeRequestInsert(anyLong(),
- any(SupervisedUserContentProvider.SupervisedUserInsertReply.class),
- anyString());
- TestRunnable r1 = new TestRunnable();
- Thread t1 = new Thread(r1);
- sLatch = new CountDownLatch(1);
- t1.start();
- sLatch.await();
- Robolectric.runUiThreadTasks();
- t1.join();
- verify(mSupervisedUserContentProvider)
- .nativeRequestInsert(eq(1234L),
- any(SupervisedUserContentProvider.SupervisedUserInsertReply.class),
- eq("url"));
- assertThat(r1.getResult(), is(true));
- assertThat(mNativeCallLooper, is(Looper.getMainLooper()));
- doAnswer(new Answer<Void>() {
-
- @Override
- public Void answer(InvocationOnMock invocation) throws Throwable {
- Object args[] = invocation.getArguments();
- mNativeCallLooper = Looper.myLooper();
- ((SupervisedUserContentProvider.SupervisedUserInsertReply) args[1])
- .onInsertRequestSendComplete(false);
- return null;
- }
-
- })
- .when(mSupervisedUserContentProvider)
- .nativeRequestInsert(anyLong(),
- any(SupervisedUserContentProvider.SupervisedUserInsertReply.class),
- anyString());
- TestRunnable r2 = new TestRunnable();
- Thread t2 = new Thread(r2);
- sLatch = new CountDownLatch(1);
- t2.start();
- sLatch.await();
- Robolectric.runUiThreadTasks();
- t2.join();
- Robolectric.runUiThreadTasks();
- verify(mSupervisedUserContentProvider, times(2))
- .nativeRequestInsert(eq(1234L),
- any(SupervisedUserContentProvider.SupervisedUserInsertReply.class),
- eq("url"));
- assertThat(r2.getResult(), is(false));
- assertThat(mNativeCallLooper, is(Looper.getMainLooper()));
- }
-}
diff --git a/chrome/browser/android/chrome_jni_registrar.cc b/chrome/browser/android/chrome_jni_registrar.cc
index 579732a..b24d754 100644
--- a/chrome/browser/android/chrome_jni_registrar.cc
+++ b/chrome/browser/android/chrome_jni_registrar.cc
@@ -112,7 +112,6 @@
#include "chrome/browser/ssl/security_state_model_android.h"
#include "chrome/browser/supervised_user/child_accounts/child_account_feedback_reporter_android.h"
#include "chrome/browser/supervised_user/child_accounts/child_account_service_android.h"
-#include "chrome/browser/supervised_user/supervised_user_content_provider_android.h"
#include "chrome/browser/sync/profile_sync_service_android.h"
#include "chrome/browser/ui/android/autofill/autofill_dialog_controller_android.h"
#include "chrome/browser/ui/android/autofill/autofill_dialog_result.h"
@@ -335,7 +334,6 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = {
{"SSLClientCertificateRequest", RegisterSSLClientCertificateRequestAndroid},
{"StartupMetricUtils", RegisterStartupMetricUtils},
{"StaticTabSceneLayer", chrome::android::RegisterStaticTabSceneLayer},
- {"SupervisedUserContentProvider", SupervisedUserContentProvider::Register},
{"Sync", syncer::RegisterSyncJni},
{"TabAndroid", TabAndroid::RegisterTabAndroid},
{"TabContentManager", chrome::android::RegisterTabContentManager},
diff --git a/chrome/browser/android/preferences/pref_service_bridge.cc b/chrome/browser/android/preferences/pref_service_bridge.cc
index e86b6c4..bfd5d66 100644
--- a/chrome/browser/android/preferences/pref_service_bridge.cc
+++ b/chrome/browser/android/preferences/pref_service_bridge.cc
@@ -953,10 +953,3 @@ std::string PrefServiceBridge::GetAndroidPermissionForContentSetting(
return ConvertJavaStringToUTF8(android_permission);
}
-
-static void SetSupervisedUserId(JNIEnv* env,
- const JavaParamRef<jobject>& obj,
- const JavaParamRef<jstring>& pref) {
- GetPrefService()->SetString(prefs::kSupervisedUserId,
- ConvertJavaStringToUTF8(env, pref));
-}
diff --git a/chrome/browser/supervised_user/supervised_user_content_provider_android.cc b/chrome/browser/supervised_user/supervised_user_content_provider_android.cc
deleted file mode 100644
index d5881a2..0000000
--- a/chrome/browser/supervised_user/supervised_user_content_provider_android.cc
+++ /dev/null
@@ -1,141 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/supervised_user/supervised_user_content_provider_android.h"
-
-#include "base/android/jni_android.h"
-#include "base/android/jni_string.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/profiles/profile_manager.h"
-#include "chrome/browser/supervised_user/supervised_user_interstitial.h"
-#include "chrome/browser/supervised_user/supervised_user_service.h"
-#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
-#include "jni/SupervisedUserContentProvider_jni.h"
-
-using base::android::JavaRef;
-using base::android::JavaParamRef;
-using base::android::ScopedJavaGlobalRef;
-using base::android::AttachCurrentThread;
-
-namespace {
-
-class UrlFilterObserver : public SupervisedUserURLFilter::Observer {
- public:
- UrlFilterObserver(JNIEnv* env,
- const ScopedJavaGlobalRef<jobject>& java_content_provider)
- : java_content_provider_(java_content_provider) {}
-
- virtual ~UrlFilterObserver() {}
-
- private:
- void OnSiteListUpdated() override {
- Java_SupervisedUserContentProvider_onSupervisedUserFilterUpdated(
- AttachCurrentThread(), java_content_provider_.obj());
- }
- ScopedJavaGlobalRef<jobject> java_content_provider_;
-};
-
-} // namespace
-
-static jlong CreateSupervisedUserContentProvider(
- JNIEnv* env,
- const JavaParamRef<jobject>& caller) {
- return reinterpret_cast<intptr_t>(
- new SupervisedUserContentProvider(env, caller));
-}
-
-SupervisedUserContentProvider::SupervisedUserContentProvider(
- JNIEnv* env,
- const JavaParamRef<jobject>& caller)
- : profile_(ProfileManager::GetLastUsedProfile()),
- java_content_provider_(env, caller),
- weak_factory_(this) {
- if (profile_->IsSupervised()) {
- SupervisedUserService* supervised_user_service =
- SupervisedUserServiceFactory::GetForProfile(profile_);
- SupervisedUserURLFilter* url_filter =
- supervised_user_service->GetURLFilterForUIThread();
- url_filter->AddObserver(new UrlFilterObserver(env, java_content_provider_));
- }
-}
-
-SupervisedUserContentProvider::~SupervisedUserContentProvider() {}
-
-void SupervisedUserContentProvider::ShouldProceed(
- JNIEnv* env,
- const JavaParamRef<jobject>& caller,
- const JavaParamRef<jobject>& query_result_jobj,
- const JavaParamRef<jstring>& url) {
- if (!profile_->IsSupervised()) {
- // User isn't supervised
- Java_SupervisedUserQueryReply_onQueryComplete(env, query_result_jobj.obj(),
- true, nullptr);
- return;
- }
- SupervisedUserService* supervised_user_service =
- SupervisedUserServiceFactory::GetForProfile(profile_);
- SupervisedUserURLFilter* url_filter =
- supervised_user_service->GetURLFilterForUIThread();
- url_filter->GetFilteringBehaviorForURLWithAsyncChecks(
- GURL(base::android::ConvertJavaStringToUTF16(env, url)),
- base::Bind(&SupervisedUserContentProvider::OnQueryComplete,
- weak_factory_.GetWeakPtr(),
- ScopedJavaGlobalRef<jobject>(env, query_result_jobj.obj())));
-}
-
-void SupervisedUserContentProvider::RequestInsert(
- JNIEnv* env,
- const JavaParamRef<jobject>& caller,
- const JavaParamRef<jobject>& insert_result_jobj,
- const JavaParamRef<jstring>& url) {
- if (!profile_->IsSupervised())
- return;
- SupervisedUserService* supervised_user_service =
- SupervisedUserServiceFactory::GetForProfile(profile_);
- supervised_user_service->AddURLAccessRequest(
- GURL(base::android::ConvertJavaStringToUTF16(env, url)),
- base::Bind(&SupervisedUserContentProvider::OnInsertRequestSendComplete,
- weak_factory_.GetWeakPtr(),
- ScopedJavaGlobalRef<jobject>(env, insert_result_jobj.obj())));
-}
-
-void SupervisedUserContentProvider::OnQueryComplete(
- ScopedJavaGlobalRef<jobject> query_reply_jobj,
- SupervisedUserURLFilter::FilteringBehavior behavior,
- SupervisedUserURLFilter::FilteringBehaviorReason reason,
- bool /* uncertain */) {
- if (behavior != SupervisedUserURLFilter::BLOCK) {
- Java_SupervisedUserQueryReply_onQueryComplete(
- AttachCurrentThread(), query_reply_jobj.obj(), true, nullptr);
- } else {
- JNIEnv* env = AttachCurrentThread();
- Java_SupervisedUserQueryReply_onQueryComplete(
- env, query_reply_jobj.obj(), false,
- base::android::ConvertUTF8ToJavaString(
- env, SupervisedUserInterstitial::GetHTMLContents(profile_, reason))
- .obj());
- }
-}
-
-void SupervisedUserContentProvider::SetFilterForTesting(JNIEnv* env,
- jobject caller) {
- if (!profile_->IsSupervised())
- return;
- SupervisedUserService* supervised_user_service =
- SupervisedUserServiceFactory::GetForProfile(profile_);
- SupervisedUserURLFilter* url_filter =
- supervised_user_service->GetURLFilterForUIThread();
- url_filter->SetDefaultFilteringBehavior(SupervisedUserURLFilter::BLOCK);
-}
-
-void SupervisedUserContentProvider::OnInsertRequestSendComplete(
- ScopedJavaGlobalRef<jobject> insert_reply_jobj,
- bool sent_ok) {
- Java_SupervisedUserInsertReply_onInsertRequestSendComplete(
- AttachCurrentThread(), insert_reply_jobj.obj(), sent_ok);
-}
-
-bool SupervisedUserContentProvider::Register(JNIEnv* env) {
- return RegisterNativesImpl(env);
-}
diff --git a/chrome/browser/supervised_user/supervised_user_content_provider_android.h b/chrome/browser/supervised_user/supervised_user_content_provider_android.h
deleted file mode 100644
index d1b6431a..0000000
--- a/chrome/browser/supervised_user/supervised_user_content_provider_android.h
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_CONTENT_PROVIDER_ANDROID_H_
-#define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_CONTENT_PROVIDER_ANDROID_H_
-
-#include <jni.h>
-#include "base/android/scoped_java_ref.h"
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "chrome/browser/supervised_user/supervised_user_url_filter.h"
-
-class SupervisedUserService;
-
-class SupervisedUserContentProvider {
- public:
- SupervisedUserContentProvider(
- JNIEnv* env,
- const base::android::JavaParamRef<jobject>& caller);
- virtual ~SupervisedUserContentProvider();
-
- void ShouldProceed(
- JNIEnv* env,
- const base::android::JavaParamRef<jobject>& caller,
- const base::android::JavaParamRef<jobject>& query_result_jobj,
- const base::android::JavaParamRef<jstring>& url);
- void RequestInsert(
- JNIEnv* env,
- const base::android::JavaParamRef<jobject>& caller,
- const base::android::JavaParamRef<jobject>& insert_result_jobj,
- const base::android::JavaParamRef<jstring>& url);
-
- void SetFilterForTesting(JNIEnv* env, jobject caller);
-
- static bool Register(JNIEnv* env);
-
- private:
- void OnQueryComplete(
- base::android::ScopedJavaGlobalRef<jobject> query_reply_jobj,
- SupervisedUserURLFilter::FilteringBehavior behavior,
- SupervisedUserURLFilter::FilteringBehaviorReason reason,
- bool /* uncertain */);
- void OnInsertRequestSendComplete(
- base::android::ScopedJavaGlobalRef<jobject> insert_reply_jobj,
- bool sent_ok);
- Profile* profile_;
- base::android::ScopedJavaGlobalRef<jobject> java_content_provider_;
-
- base::WeakPtrFactory<SupervisedUserContentProvider> weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(SupervisedUserContentProvider);
-};
-
-#endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_CONTENT_PROVIDER_ANDROID_H_
diff --git a/chrome/browser/supervised_user/supervised_user_interstitial.cc b/chrome/browser/supervised_user/supervised_user_interstitial.cc
index f53271c..510c783 100644
--- a/chrome/browser/supervised_user/supervised_user_interstitial.cc
+++ b/chrome/browser/supervised_user/supervised_user_interstitial.cc
@@ -195,35 +195,32 @@ bool SupervisedUserInterstitial::Init() {
return true;
}
-// static
-std::string SupervisedUserInterstitial::GetHTMLContents(
- Profile* profile,
- SupervisedUserURLFilter::FilteringBehaviorReason reason) {
+std::string SupervisedUserInterstitial::GetHTMLContents() {
base::DictionaryValue strings;
strings.SetString("blockPageTitle",
l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE));
SupervisedUserService* supervised_user_service =
- SupervisedUserServiceFactory::GetForProfile(profile);
+ SupervisedUserServiceFactory::GetForProfile(profile_);
bool allow_access_requests = supervised_user_service->AccessRequestsEnabled();
strings.SetBoolean("allowAccessRequests", allow_access_requests);
- std::string profile_image_url = profile->GetPrefs()->GetString(
+ std::string profile_image_url = profile_->GetPrefs()->GetString(
prefs::kSupervisedUserCustodianProfileImageURL);
strings.SetString("avatarURL1x", BuildAvatarImageUrl(profile_image_url,
kAvatarSize1x));
strings.SetString("avatarURL2x", BuildAvatarImageUrl(profile_image_url,
kAvatarSize2x));
- std::string profile_image_url2 = profile->GetPrefs()->GetString(
+ std::string profile_image_url2 = profile_->GetPrefs()->GetString(
prefs::kSupervisedUserSecondCustodianProfileImageURL);
strings.SetString("secondAvatarURL1x", BuildAvatarImageUrl(profile_image_url2,
kAvatarSize1x));
strings.SetString("secondAvatarURL2x", BuildAvatarImageUrl(profile_image_url2,
kAvatarSize2x));
- bool is_child_account = profile->IsChild();
+ bool is_child_account = profile_->IsChild();
base::string16 custodian =
base::UTF8ToUTF16(supervised_user_service->GetCustodianName());
@@ -246,16 +243,15 @@ std::string SupervisedUserInterstitial::GetHTMLContents(
IDS_BLOCK_INTERSTITIAL_MESSAGE_ACCESS_REQUESTS_DISABLED);
}
strings.SetString("blockPageMessage", block_message);
- strings.SetString(
- "blockReasonMessage",
- is_child_account ? l10n_util::GetStringUTF16(
- SupervisedUserURLFilter::GetBlockMessageID(reason))
- : base::string16());
+ strings.SetString("blockReasonMessage", is_child_account
+ ? l10n_util::GetStringUTF16(
+ SupervisedUserURLFilter::GetBlockMessageID(reason_))
+ : base::string16());
bool show_feedback = false;
#if defined(GOOGLE_CHROME_BUILD)
- show_feedback =
- is_child_account && SupervisedUserURLFilter::ReasonIsAutomatic(reason);
+ show_feedback = is_child_account &&
+ SupervisedUserURLFilter::ReasonIsAutomatic(reason_);
#endif
strings.SetBoolean("showFeedbackLink", show_feedback);
strings.SetString("feedbackLink",
@@ -302,10 +298,6 @@ std::string SupervisedUserInterstitial::GetHTMLContents(
return webui::GetI18nTemplateHtml(html, &strings);
}
-std::string SupervisedUserInterstitial::GetHTMLContents() {
- return GetHTMLContents(profile_, reason_);
-}
-
void SupervisedUserInterstitial::CommandReceived(const std::string& command) {
// For use in histograms.
enum Commands {
diff --git a/chrome/browser/supervised_user/supervised_user_interstitial.h b/chrome/browser/supervised_user/supervised_user_interstitial.h
index ca28048..bf75f13 100644
--- a/chrome/browser/supervised_user/supervised_user_interstitial.h
+++ b/chrome/browser/supervised_user/supervised_user_interstitial.h
@@ -35,10 +35,6 @@ class SupervisedUserInterstitial : public content::InterstitialPageDelegate,
SupervisedUserURLFilter::FilteringBehaviorReason reason,
const base::Callback<void(bool)>& callback);
- static std::string GetHTMLContents(
- Profile* profile,
- SupervisedUserURLFilter::FilteringBehaviorReason reason);
-
private:
SupervisedUserInterstitial(
content::WebContents* web_contents,
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index d8c21a9..971ee9f 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -567,7 +567,6 @@
'../components/components.gyp:signin_core_browser_java',
'../components/components.gyp:variations_java',
'../components/components.gyp:web_contents_delegate_android_java',
- '../components/components.gyp:web_restriction_java',
'../components/components_strings.gyp:components_strings',
'../content/content.gyp:content_java',
'../media/media.gyp:media_java',
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 2dbcc49..5763ed6 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1892,7 +1892,6 @@
'android/java/src/org/chromium/chrome/browser/signin/SigninManager.java',
'android/java/src/org/chromium/chrome/browser/snackbar/smartlockautosignin/AutoSigninSnackbarController.java',
'android/java/src/org/chromium/chrome/browser/spellchecker/SpellCheckerSessionBridge.java',
- 'android/java/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProvider.java',
'android/java/src/org/chromium/chrome/browser/sync/ProfileSyncService.java',
'android/java/src/org/chromium/chrome/browser/tab/Tab.java',
'android/java/src/org/chromium/chrome/browser/tab/TabWebContentsDelegateAndroid.java',
@@ -2862,8 +2861,6 @@
'browser/supervised_user/supervised_user_bookmarks_handler.h',
'browser/supervised_user/supervised_user_constants.cc',
'browser/supervised_user/supervised_user_constants.h',
- 'browser/supervised_user/supervised_user_content_provider_android.cc',
- 'browser/supervised_user/supervised_user_content_provider_android.h',
'browser/supervised_user/supervised_user_interstitial.cc',
'browser/supervised_user/supervised_user_interstitial.h',
'browser/supervised_user/supervised_user_navigation_observer.cc',