Index: components/web_restriction/content_resolver_web_restriction_provider.cc |
diff --git a/components/web_restriction/content_resolver_web_restriction_provider.cc b/components/web_restriction/content_resolver_web_restriction_provider.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..906f8c57362cf32bbbb7382d77a254fb2d2277ef |
--- /dev/null |
+++ b/components/web_restriction/content_resolver_web_restriction_provider.cc |
@@ -0,0 +1,119 @@ |
+// 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 "components/web_restriction/content_resolver_web_restriction_provider.h" |
+ |
+#include "base/android/jni_string.h" |
+#include "base/android/scoped_java_ref.h" |
+#include "jni/ContentResolverWebRestrictionProvider_jni.h" |
+ |
+namespace web_restriction { |
+namespace android { |
+ |
+SelfDeletingCallback::SelfDeletingCallback( |
+ const GURL& url, |
+ const base::Callback<void(bool)>& callback) |
+ : url_(url), callback_(callback) {} |
+ |
+SelfDeletingCallback::~SelfDeletingCallback() {} |
+ |
+void SelfDeletingCallback::ShouldProceed( |
+ JNIEnv* env, |
+ const base::android::JavaParamRef<jobject>& obj, |
+ jboolean should_proceed) { |
+ // TODO Update cache |
Bernhard Bauer
2016/01/22 17:32:31
What cache?
knn
2016/01/25 11:54:24
Cache of known statuses.
|
+ callback_.Run(should_proceed); |
+ delete this; |
+} |
+ |
+} // namespace android |
+ |
+ContentResolverWebRestrictionProvider::ContentResolverWebRestrictionProvider() { |
+ initialized_ = false; |
+} |
+ |
+ContentResolverWebRestrictionProvider:: |
+ ~ContentResolverWebRestrictionProvider() {} |
+ |
+// static |
+bool ContentResolverWebRestrictionProvider::Register(JNIEnv* env) { |
+ return android::RegisterNativesImpl(env); |
+} |
+ |
+void ContentResolverWebRestrictionProvider::Initialize( |
+ const std::string& content_provider_authority) { |
+ DCHECK(!initialized_); |
+ DCHECK(!content_provider_authority.empty()); |
+ // TODO Check if valid authority |
+ initialized_ = true; |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ java_provider_.Reset( |
+ android::Java_ContentResolverWebRestrictionProvider_create( |
+ env, base::android::ConvertUTF8ToJavaString( |
+ env, content_provider_authority) |
+ .obj())); |
+ supports_request_ = |
+ android::Java_ContentResolverWebRestrictionProvider_supportsRequest( |
+ env, java_provider_.obj()); |
+ ScopedJavaLocalRef<jstring> j_error_page = |
+ android::Java_ContentResolverWebRestrictionProvider_getErrorPage( |
aberent
2016/01/21 12:00:43
The error page isn't set until there is a response
knn
2016/01/21 12:17:22
My bad.
|
+ env, java_provider_.obj()); |
+ if (!j_error_page.is_null()) { |
+ error_page_ = base::android::ConvertJavaStringToUTF8(j_error_page); |
+ } else { |
+ error_page_ = ""; |
Bernhard Bauer
2016/01/22 17:32:31
.clear()
knn
2016/01/25 11:54:24
Done.
|
+ } |
+} |
+ |
+UrlAccess ContentResolverWebRestrictionProvider::ShouldProceed( |
+ bool is_main_frame, |
+ const GURL& url) const { |
+ if (!initialized_) |
+ return ALLOW; |
+ // TODO: Implement Cache here. |
+ return UNKNOWN; |
+} |
+ |
+void ContentResolverWebRestrictionProvider::ShouldProceed( |
+ bool is_main_frame, |
+ const GURL& url, |
+ const base::Callback<void(bool)>& callback) const { |
+ // This should only be called after hitting the cache first. |
+ DCHECK(initialized_); |
+ // This will delete itself on being called. |
+ android::SelfDeletingCallback* wrapped_callback = |
+ new android::SelfDeletingCallback(url, callback); |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ android::Java_ContentResolverWebRestrictionProvider_shouldProceed( |
+ env, java_provider_.obj(), reinterpret_cast<jlong>(wrapped_callback), |
+ base::android::ConvertUTF8ToJavaString(env, url.spec()).obj()); |
+} |
+ |
+bool ContentResolverWebRestrictionProvider::SupportsRequest() const { |
+ return supports_request_; |
+} |
+ |
+bool ContentResolverWebRestrictionProvider::SupportsCustomErrorPage() const { |
+ return !error_page_.empty(); |
+} |
+ |
+std::string ContentResolverWebRestrictionProvider::GetErrorHtml() const { |
+ DCHECK(SupportsCustomErrorPage()); |
+ return error_page_; |
+} |
+ |
+void ContentResolverWebRestrictionProvider::RequestPermission(const GURL& url) { |
+ // Throttling should be implemented by the Content Provider? |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ android::Java_ContentResolverWebRestrictionProvider_requestPermission( |
+ env, java_provider_.obj(), |
+ base::android::ConvertUTF8ToJavaString(env, url.spec()).obj()); |
+} |
+ |
+void ContentResolverWebRestrictionProvider::AddObserver(Observer* observer) {} |
+ |
+void ContentResolverWebRestrictionProvider::RemoveObserver(Observer* observer) { |
+} |
+ |
+} // namespace web_restriction |