| Index: components/web_restrictions/content_resolver_web_restrictions_provider.h
|
| diff --git a/components/web_restrictions/content_resolver_web_restrictions_provider.h b/components/web_restrictions/content_resolver_web_restrictions_provider.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..902d4bff271aac785702fa4462e38cc2dc2462eb
|
| --- /dev/null
|
| +++ b/components/web_restrictions/content_resolver_web_restrictions_provider.h
|
| @@ -0,0 +1,99 @@
|
| +// 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_restrictions/web_restrictions_provider.h"
|
| +
|
| +namespace web_restrictions {
|
| +
|
| +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 query it for basic information like does it
|
| + // support handling requests. This should be called everytime the provider
|
| + // changes.
|
| + 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_;
|
| + // Set up 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_restrictions
|
| +
|
| +#endif // COMPONENTS_WEB_RESTRICTION_CONTENT_RESOLVER_WEB_RESTRICTION_PROVIDER_H_
|
|
|