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..daa0a9f540938b3b4692ebdc491f701d943cb4af |
--- /dev/null |
+++ b/components/web_restriction/java/src/org/chromium/components/web_restriction/ContentResolverWebRestrictionProvider.java |
@@ -0,0 +1,74 @@ |
+// 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; |
Bernhard Bauer
2016/01/22 17:32:31
Don't use underscores in Java package names, i.e.
knn
2016/01/25 11:54:24
Done.
|
+ |
+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.ContextUtils; |
+import org.chromium.base.annotations.CalledByNative; |
+import org.chromium.base.annotations.JNINamespace; |
+ |
+@JNINamespace("web_restriction::android") |
+public class ContentResolverWebRestrictionProvider { |
+ private final Context mContext; |
+ |
+ private final Uri mRequestUri; |
+ private final Uri mQueryUri; |
+ private boolean mSupportsRequest; |
+ private String mErrorPage; |
+ |
+ private ContentResolverWebRestrictionProvider(String authority) { |
+ assert !TextUtils.isEmpty(authority); |
+ Uri baseUri = new Uri.Builder().scheme("content").authority(authority).build(); |
+ mContext = ContextUtils.getApplicationContext(); |
+ mSupportsRequest = mContext.getContentResolver().getType(baseUri) != null; |
Bernhard Bauer
2016/01/22 17:32:31
That's clever! I would probably do this for the re
knn
2016/01/25 11:54:24
Done.
TODO: We will need to update the Content Pro
|
+ mRequestUri = mSupportsRequest ? Uri.withAppendedPath(baseUri, "requested") : null; |
+ mQueryUri = Uri.withAppendedPath(baseUri, "authorized"); |
+ } |
+ |
+ @CalledByNative |
+ private static ContentResolverWebRestrictionProvider create(String authority) { |
+ return new ContentResolverWebRestrictionProvider(authority); |
+ } |
+ |
+ @CalledByNative |
+ private boolean supportsRequest() { |
+ return mSupportsRequest; |
+ } |
+ |
+ @CalledByNative |
+ private String getErrorPage() { |
+ return mErrorPage; |
+ } |
+ |
+ @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 = result == null || result.getInt(0) > 0; |
+ mErrorPage = result.getString(1); |
+ nativeShouldProceed(nativeCallback, shouldProceed); |
+ } |
+ }.startQuery(0, null, mQueryUri, null, url, null, null); |
aberent
2016/01/21 12:00:43
I think mQueryUri needs to be "url = <mQueryUri>"
knn
2016/01/21 12:17:22
You probably mean the |url| field = "url = 'blah'"
|
+ } |
+ |
+ @CalledByNative |
+ private void requestPermission(final String url) { |
+ // TODO register for updates |
+ ContentValues values = new ContentValues(1); |
+ values.put("url", url); |
+ new AsyncQueryHandler(mContext.getContentResolver()) { |
+ // Don't care about completion notifications. |
aberent
2016/01/21 12:00:43
Maybe you do. Insert will return null if something
knn
2016/01/21 12:17:22
Good point!
|
+ }.startInsert(0, null, mRequestUri, values); |
+ } |
+ |
+ private native void nativeShouldProceed(long nativeSelfDeletingCallback, boolean shouldProceed); |
+} |