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 #include <list> | |
| 10 #include <map> | |
| 11 | |
| 12 #include "base/android/jni_android.h" | |
| 13 #include "base/callback.h" | |
| 14 #include "base/macros.h" | |
| 15 #include "base/memory/ref_counted.h" | |
| 16 #include "base/sequenced_task_runner.h" | |
| 17 #include "base/single_thread_task_runner.h" | |
| 18 #include "components/web_restrictions/web_restrictions_provider.h" | |
| 19 | |
| 20 namespace web_restrictions { | |
| 21 | |
| 22 class ContentResolverWebRestrictionsProvider : public WebRestrictionsProvider { | |
| 23 public: | |
| 24 // An instance of this class is expected to live through the lifetime of a | |
| 25 // browser and uses raw pointers in callbacks. | |
| 26 // Any changes to the class, enable/disable/change should be done through the | |
| 27 // SetAuthority(...) method. | |
| 28 ContentResolverWebRestrictionsProvider(); | |
| 29 ~ContentResolverWebRestrictionsProvider() override; | |
| 30 | |
| 31 // Register JNI methods. | |
| 32 static bool Register(JNIEnv* env); | |
| 33 | |
| 34 // Verify the content provider and query it for basic information like does it | |
| 35 // support handling requests. This should be called everytime the provider | |
| 36 // changes. An empty authority can be used to disable this class. | |
| 37 void SetAuthority(const std::string& content_provider_authority); | |
| 38 | |
| 39 // WebRestrictionsProvider: | |
| 40 UrlAccess ShouldProceed(bool is_main_frame, | |
| 41 const GURL& url, | |
| 42 const base::Callback<void(bool)>& callback) override; | |
| 43 | |
| 44 bool SupportsRequest() const override; | |
| 45 | |
| 46 bool GetErrorHtml(const GURL& url, std::string* error_html) const override; | |
| 47 | |
| 48 void RequestPermission(const GURL& url, | |
| 49 const base::Callback<void(bool)>& callback) override; | |
| 50 | |
| 51 void OnWebRestrictionsChanged(); | |
| 52 | |
| 53 private: | |
| 54 friend class SelfDeletingCallback; // For updating the cache. | |
| 55 | |
| 56 void RecordURLAccess(const GURL& url); | |
| 57 | |
| 58 void UpdateCache(std::string provider_authority, | |
|
Bernhard Bauer
2016/02/04 11:13:53
Pass by const-ref.
knn
2016/02/04 13:09:27
Passed in a callback from SelfDeletingCallback so
| |
| 59 GURL url, | |
| 60 bool should_proceed, | |
| 61 std::string error_page); | |
| 62 | |
| 63 void RequestSupportKnown(std::string provider_authority, | |
| 64 bool supports_request); | |
| 65 | |
| 66 void ClearCache(); | |
| 67 | |
| 68 // Set up after SetAuthority(). | |
| 69 bool initialized_; | |
| 70 bool supports_request_; | |
| 71 base::android::ScopedJavaGlobalRef<jobject> java_provider_; | |
| 72 std::string provider_authority_; | |
| 73 | |
| 74 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; | |
| 75 scoped_refptr<base::SingleThreadTaskRunner> single_thread_task_runner_; | |
| 76 | |
| 77 std::map<GURL, std::string> error_page_cache_; | |
| 78 std::map<GURL, bool> url_access_cache_; | |
| 79 std::list<GURL> recent_urls_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(ContentResolverWebRestrictionsProvider); | |
| 82 }; | |
| 83 | |
| 84 } // namespace web_restrictions | |
| 85 | |
| 86 #endif // COMPONENTS_WEB_RESTRICTION_CONTENT_RESOLVER_WEB_RESTRICTION_PROVIDER_ H_ | |
| OLD | NEW |