Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(974)

Unified Diff: components/web_restrictions/browser/javatest/src/org/chromium/components/webrestrictions/WebRestrictionsClient.java

Issue 1684153002: Web restrictions component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary file Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/web_restrictions/browser/javatest/src/org/chromium/components/webrestrictions/WebRestrictionsClient.java
diff --git a/components/web_restrictions/browser/javatest/src/org/chromium/components/webrestrictions/WebRestrictionsClient.java b/components/web_restrictions/browser/javatest/src/org/chromium/components/webrestrictions/WebRestrictionsClient.java
new file mode 100644
index 0000000000000000000000000000000000000000..e955d539cb9141a4e4e718115833fe2b5b6d7c34
--- /dev/null
+++ b/components/web_restrictions/browser/javatest/src/org/chromium/components/webrestrictions/WebRestrictionsClient.java
@@ -0,0 +1,92 @@
+// 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.components.webrestrictions;
+
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
+
+/**
+ * This is a dummy version of the real WebRestrictionsClient, to allow unit testing of the C++
+ * code.
+ */
+@JNINamespace("web_restrictions")
+public class WebRestrictionsClient {
+ private class ShouldProceedResult {
+ private final boolean mShouldProceed;
+ private final String mErrorPage;
+
+ ShouldProceedResult(boolean shouldProceed, String errorPage) {
+ mShouldProceed = shouldProceed;
+ mErrorPage = errorPage;
+ }
+
+ @CalledByNative("ShouldProceedResult")
+ boolean shouldProceed() {
+ return mShouldProceed;
+ }
+
+ @CalledByNative("ShouldProceedResult")
+ String getErrorPage() {
+ return mErrorPage;
+ }
+ }
+
+ private String mAuthority;
+
+ /**
+ * Start the web restriction provider and setup the content resolver.
+ */
+ WebRestrictionsClient() {}
+
+ void init(String authority, final long nativeProvider) {
+ mAuthority = authority;
+ }
+
+ /**
+ * Simple helper method to expose the constructor over JNI.
+ */
+ @CalledByNative
+ private static WebRestrictionsClient create(String authority, long nativeProvider) {
+ WebRestrictionsClient client = new WebRestrictionsClient();
+ client.init(authority, nativeProvider);
+ return client;
+ }
+
+ /**
+ * @return whether the web restriction provider supports requesting access for a blocked url.
+ */
+ @CalledByNative
+ boolean supportsRequest() {
+ return mAuthority.contains("Good");
+ }
+
+ /**
+ * Called when the ContentResolverWebRestrictionsProvider is about to be destroyed.
+ */
+ @CalledByNative
+ private void onDestroy() {}
+
+ /**
+ * Whether we can proceed with loading the {@code url}.
+ * In case the url is not to be loaded, the web restriction provider can return an optional
+ * error page to show instead.
+ */
+ @CalledByNative
+ ShouldProceedResult shouldProceed(final String url) {
+ return new ShouldProceedResult(mAuthority.contains("Good"), url);
+ }
+
+ /**
+ * Request permission to load the {@code url}.
+ * The web restriction provider returns a {@code boolean} variable indicating whether it was
+ * able to forward the request to the appropriate authority who can approve it.
+ */
+ @CalledByNative
+ boolean requestPermission(final String url) {
+ return mAuthority.contains("Good");
+ }
+
+ native void nativeNotifyWebRestrictionsChanged(long ptrProvider);
+}

Powered by Google App Engine
This is Rietveld 408576698