Chromium Code Reviews| 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..870331d7a41786a43de6d2adf40c6711484945d7 |
| --- /dev/null |
| +++ b/components/web_restriction/content_resolver_web_restriction_provider.h |
| @@ -0,0 +1,85 @@ |
| +// 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 "base/android/jni_android.h" |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/observer_list.h" |
| +#include "components/web_restriction/web_restriction_provider.h" |
| + |
| +namespace web_restriction { |
| + |
| +namespace android { |
| +class SelfDeletingCallback { |
| + public: |
| + SelfDeletingCallback(const GURL& url, |
| + const base::Callback<void(bool)>& callback); |
| + |
| + void ShouldProceed(JNIEnv* env, |
| + const base::android::JavaParamRef<jobject>& obj, |
| + jboolean should_proceed); |
| + |
| + private: |
| + GURL url_; |
| + base::Callback<void(bool)> callback_; |
| + |
| + // Only the callback can delete itself. We must ensure it is indeed |
| + // called back. |
| + ~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 override; |
| + |
| + void ShouldProceed(bool is_main_frame, |
| + const GURL& url, |
| + const base::Callback<void(bool)>& callback) const override; |
|
aberent
2015/11/16 12:39:08
Change name to AsyncShouldProceed?
|
| + |
| + bool SupportsRequest() const override; |
| + |
| + bool SupportsCustomErrorPage() const override; |
| + |
| + std::string GetErrorHtml() const override; |
| + |
| + void RequestPermission(const GURL& url) override; |
| + |
| + void AddObserver(Observer* observer) override; |
| + |
| + void RemoveObserver(Observer* observer) override; |
| + |
| + private: |
| + friend class SelfDeletingCallback; // For updating the cache. |
| + |
| + base::ObserverList<Observer> observer_list_; |
| + base::android::ScopedJavaGlobalRef<jobject> java_provider_; |
| + |
| + // Setup during Initialize. |
| + bool initialized_; |
| + bool supports_request_; |
| + std::string error_page_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ContentResolverWebRestrictionProvider); |
| +}; |
| + |
| +} // namespace web_restriction |
| + |
| +#endif // COMPONENTS_WEB_RESTRICTION_CONTENT_RESOLVER_WEB_RESTRICTION_PROVIDER_H_ |