| Index: components/web_restriction/content_resolver_web_restriction_provider.h
|
| diff --git a/components/web_restriction/content_resolver_web_restriction_provider.h b/components/web_restriction/content_resolver_web_restriction_provider.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b651e3225b14462876bac8c95bcd4240dccefea0
|
| --- /dev/null
|
| +++ b/components/web_restriction/content_resolver_web_restriction_provider.h
|
| @@ -0,0 +1,97 @@
|
| +// 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.
|
| +
|
| +#ifndef COMPONENTS_WEB_RESTRICTION_CONTENT_RESOLVER_WEB_RESTRICTION_PROVIDER_H_
|
| +#define COMPONENTS_WEB_RESTRICTION_CONTENT_RESOLVER_WEB_RESTRICTION_PROVIDER_H_
|
| +
|
| +#include <jni.h>
|
| +#include <list>
|
| +#include <map>
|
| +
|
| +#include "base/android/jni_android.h"
|
| +#include "base/callback.h"
|
| +#include "base/macros.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/task_runner.h"
|
| +#include "components/web_restriction/web_restriction_provider.h"
|
| +
|
| +namespace web_restriction {
|
| +
|
| +class ContentResolverWebRestrictionProvider;
|
| +
|
| +namespace android {
|
| +
|
| +// A wrapper to the callback class to facilitate getting a callback from java
|
| +// into C++. Objects of this class delete itself only when they are called back
|
| +// so we must ensure that happens even for error cases.
|
| +class SelfDeletingCallback {
|
| + public:
|
| + SelfDeletingCallback(const GURL& url,
|
| + const base::Callback<void(bool)>& callback,
|
| + const scoped_refptr<base::TaskRunner>& callback_runner,
|
| + ContentResolverWebRestrictionProvider* provider);
|
| +
|
| + void RequestSuccess(JNIEnv* env,
|
| + const base::android::JavaParamRef<jobject>& obj,
|
| + jboolean request_success);
|
| + void ShouldProceed(JNIEnv* env,
|
| + const base::android::JavaParamRef<jobject>& obj,
|
| + jboolean should_proceed,
|
| + const base::android::JavaParamRef<jstring>& error_page);
|
| +
|
| + private:
|
| + GURL url_;
|
| + base::Callback<void(bool)> callback_;
|
| + scoped_refptr<base::TaskRunner> callback_runner_;
|
| + ContentResolverWebRestrictionProvider* provider_;
|
| +
|
| + // Only the callback can delete itself. We must ensure it is indeed
|
| + // called back.
|
| + ~SelfDeletingCallback();
|
| + DISALLOW_COPY_AND_ASSIGN(SelfDeletingCallback);
|
| +};
|
| +
|
| +} // namespace android
|
| +
|
| +class ContentResolverWebRestrictionProvider : public WebRestrictionProvider {
|
| + public:
|
| + ContentResolverWebRestrictionProvider();
|
| + ~ContentResolverWebRestrictionProvider() override;
|
| +
|
| + // Register JNI methods.
|
| + static bool Register(JNIEnv* env);
|
| +
|
| + // Verify the content provider and Setup.
|
| + void Initialize(const std::string& content_provider_authority);
|
| +
|
| + // WebRestrictionProvider:
|
| + UrlAccess ShouldProceed(bool is_main_frame,
|
| + const GURL& url,
|
| + const base::Callback<void(bool)>& callback) override;
|
| +
|
| + bool SupportsRequest() const override;
|
| +
|
| + bool GetErrorHtml(const GURL& url, std::string* error_html) const override;
|
| +
|
| + void RequestPermission(const GURL& url,
|
| + const base::Callback<void(bool)>& callback) override;
|
| +
|
| + private:
|
| + friend class android::SelfDeletingCallback; // For updating the cache.
|
| +
|
| + bool initialized_;
|
| + // Setup during Initialize.
|
| + bool supports_request_;
|
| + base::android::ScopedJavaGlobalRef<jobject> java_provider_;
|
| +
|
| + std::map<GURL, std::string> error_page_cache_;
|
| + std::map<GURL, bool> url_access_cache_;
|
| + std::list<GURL> recent_urls_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ContentResolverWebRestrictionProvider);
|
| +};
|
| +
|
| +} // namespace web_restriction
|
| +
|
| +#endif // COMPONENTS_WEB_RESTRICTION_CONTENT_RESOLVER_WEB_RESTRICTION_PROVIDER_H_
|
|
|