Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_WEB_RESTRICTION_CONTENT_RESOLVER_WEB_RESTRICTION_PROVIDER_H_ | |
| 6 #define COMPONENTS_WEB_RESTRICTION_CONTENT_RESOLVER_WEB_RESTRICTION_PROVIDER_H_ | |
| 7 | |
| 8 #include <jni.h> | |
| 9 | |
| 10 #include "base/android/jni_android.h" | |
| 11 #include "base/callback.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/observer_list.h" | |
| 14 #include "components/web_restriction/web_restriction_provider.h" | |
| 15 | |
| 16 namespace web_restriction { | |
| 17 | |
| 18 namespace android { | |
| 19 class SelfDeletingCallback { | |
| 20 public: | |
| 21 SelfDeletingCallback(const GURL& url, | |
| 22 const base::Callback<void(bool)>& callback); | |
| 23 | |
| 24 void ShouldProceed(JNIEnv* env, | |
| 25 const base::android::JavaParamRef<jobject>& obj, | |
| 26 jboolean should_proceed); | |
| 27 | |
| 28 private: | |
| 29 GURL url_; | |
| 30 base::Callback<void(bool)> callback_; | |
| 31 | |
| 32 // Only the callback can delete itself. We must ensure it is indeed | |
| 33 // called back. | |
| 34 ~SelfDeletingCallback(); | |
| 35 }; | |
| 36 | |
| 37 } // namespace android | |
| 38 | |
| 39 class ContentResolverWebRestrictionProvider : public WebRestrictionProvider { | |
| 40 public: | |
| 41 ContentResolverWebRestrictionProvider(); | |
| 42 ~ContentResolverWebRestrictionProvider() override; | |
| 43 | |
| 44 // Register JNI methods. | |
| 45 static bool Register(JNIEnv* env); | |
| 46 | |
| 47 // Verify the content provider and Setup. | |
| 48 void Initialize(const std::string& content_provider_authority); | |
| 49 | |
| 50 // WebRestrictionProvider: | |
| 51 UrlAccess ShouldProceed(bool is_main_frame, const GURL& url) const override; | |
| 52 | |
| 53 void ShouldProceed(bool is_main_frame, | |
| 54 const GURL& url, | |
| 55 const base::Callback<void(bool)>& callback) const override; | |
|
aberent
2015/11/16 12:39:08
Change name to AsyncShouldProceed?
| |
| 56 | |
| 57 bool SupportsRequest() const override; | |
| 58 | |
| 59 bool SupportsCustomErrorPage() const override; | |
| 60 | |
| 61 std::string GetErrorHtml() const override; | |
| 62 | |
| 63 void RequestPermission(const GURL& url) override; | |
| 64 | |
| 65 void AddObserver(Observer* observer) override; | |
| 66 | |
| 67 void RemoveObserver(Observer* observer) override; | |
| 68 | |
| 69 private: | |
| 70 friend class SelfDeletingCallback; // For updating the cache. | |
| 71 | |
| 72 base::ObserverList<Observer> observer_list_; | |
| 73 base::android::ScopedJavaGlobalRef<jobject> java_provider_; | |
| 74 | |
| 75 // Setup during Initialize. | |
| 76 bool initialized_; | |
| 77 bool supports_request_; | |
| 78 std::string error_page_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(ContentResolverWebRestrictionProvider); | |
| 81 }; | |
| 82 | |
| 83 } // namespace web_restriction | |
| 84 | |
| 85 #endif // COMPONENTS_WEB_RESTRICTION_CONTENT_RESOLVER_WEB_RESTRICTION_PROVIDER_ H_ | |
| OLD | NEW |