Index: components/web_restriction/java/src/org/chromium/components/web_restriction/ContentResolverWebRestrictionProvider.java |
diff --git a/components/web_restriction/java/src/org/chromium/components/web_restriction/ContentResolverWebRestrictionProvider.java b/components/web_restriction/java/src/org/chromium/components/web_restriction/ContentResolverWebRestrictionProvider.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8c61174f0a871f2172c243926b240c26a1724fef |
--- /dev/null |
+++ b/components/web_restriction/java/src/org/chromium/components/web_restriction/ContentResolverWebRestrictionProvider.java |
@@ -0,0 +1,72 @@ |
+// 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.web_restriction; |
+ |
+import android.content.AsyncQueryHandler; |
+import android.content.ContentValues; |
+import android.content.Context; |
+import android.database.Cursor; |
+import android.net.Uri; |
+import android.text.TextUtils; |
+ |
+import org.chromium.base.ApplicationStatus; |
+import org.chromium.base.annotations.CalledByNative; |
+import org.chromium.base.annotations.JNINamespace; |
+ |
+@JNINamespace("web_restriction::android") |
+public class ContentResolverWebRestrictionProvider { |
+ private final Uri mUri; |
+ private final Context mContext; |
+ |
+ private ContentResolverWebRestrictionProvider(String authority) { |
+ assert !TextUtils.isEmpty(authority); |
+ mUri = new Uri.Builder().scheme("content://").authority(authority).build(); |
+ // May need to change this BUG=470582 |
+ mContext = ApplicationStatus.getApplicationContext(); |
+ } |
+ |
+ @CalledByNative |
+ private static ContentResolverWebRestrictionProvider create(String authority) { |
+ return new ContentResolverWebRestrictionProvider(authority); |
+ } |
+ |
+ @CalledByNative |
+ private boolean supportsRequest() { |
+ // mContext.getContentResolver().getType() |
+ return true; |
+ } |
+ |
+ @CalledByNative |
+ private String getErrorPage() { |
+ // mContext.getContentResolver().getType() |
+ return "<!doctype html><head><title>Blocked!</title></head><body bgcolor=\"#FF0000\">" |
+ + "Blocked Body<script type=\"text/javascript\">" |
+ + "window.webRestriction.requestPermission()</script></body>"; |
+ } |
+ |
+ @CalledByNative |
+ private void shouldProceed(final long nativeCallback, final String url) { |
+ new AsyncQueryHandler(mContext.getContentResolver()) { |
+ @Override |
+ protected void onQueryComplete(int token, Object cookie, Cursor result) { |
+ boolean shouldProceed = false; |
+ // get result from cursor |
+ nativeShouldProceed(nativeCallback, shouldProceed); |
+ } |
+ }.startQuery(0, null, mUri, null, url, null, null); |
aberent
2015/11/16 12:39:08
The startQuery documentation says that the 5 argum
|
+ } |
+ |
+ @CalledByNative |
+ private void requestPermission(final String url) { |
+ // TODO register for updates |
+ ContentValues values = new ContentValues(1); |
+ values.put("request", url); |
+ new AsyncQueryHandler(mContext.getContentResolver()) { |
+ // Don't care about completion notifications. |
+ }.startInsert(0, null, mUri, values); |
+ } |
+ |
+ private native void nativeShouldProceed(long nativeSelfDeletingCallback, boolean shouldProceed); |
+} |