| 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..b45a1597b26f82dc5675ccfd57753956b3719a4a
|
| --- /dev/null
|
| +++ b/components/web_restriction/content_resolver_web_restriction_provider.cc
|
| @@ -0,0 +1,115 @@
|
| +// 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
|
| + callback_.Run(should_proceed);
|
| + delete this;
|
| +}
|
| +
|
| +} // namespace android
|
| +
|
| +ContentResolverWebRestrictionProvider::ContentResolverWebRestrictionProvider() {
|
| +}
|
| +
|
| +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(
|
| + env, java_provider_.obj());
|
| + if (!j_error_page.is_null())
|
| + error_page_ = base::android::ConvertJavaStringToUTF8(j_error_page);
|
| +}
|
| +
|
| +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
|
|
|