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/task_runner.h" | |
17 #include "components/web_restriction/web_restriction_provider.h" | |
18 | |
19 namespace web_restriction { | |
20 | |
21 class ContentResolverWebRestrictionProvider; | |
22 | |
23 namespace android { | |
24 | |
25 // A wrapper to the callback class to facilitate getting a callback from java | |
26 // into C++. Objects of this class delete itself only when they are called back | |
27 // so we must ensure that happens even for error cases. | |
28 class SelfDeletingCallback { | |
Bernhard Bauer
2016/01/26 11:09:03
Why is this in the header? We should be able to mo
knn
2016/01/26 14:37:43
We need this class to be declared before the jni h
Bernhard Bauer
2016/01/27 14:24:01
Hm. What we really need is just a declaration of t
knn
2016/01/28 11:43:25
Resolved the issue by casting to the callback myse
| |
29 public: | |
30 SelfDeletingCallback(const GURL& url, | |
31 const base::Callback<void(bool)>& callback, | |
32 const scoped_refptr<base::TaskRunner>& callback_runner, | |
33 ContentResolverWebRestrictionProvider* provider); | |
34 | |
35 void RequestSuccess(JNIEnv* env, | |
36 const base::android::JavaParamRef<jobject>& obj, | |
37 jboolean request_success); | |
38 void ShouldProceed(JNIEnv* env, | |
39 const base::android::JavaParamRef<jobject>& obj, | |
40 jboolean should_proceed, | |
41 const base::android::JavaParamRef<jstring>& error_page); | |
42 | |
43 private: | |
44 GURL url_; | |
45 base::Callback<void(bool)> callback_; | |
46 scoped_refptr<base::TaskRunner> callback_runner_; | |
47 ContentResolverWebRestrictionProvider* provider_; | |
48 | |
49 // Only the callback can delete itself. We must ensure it is indeed | |
50 // called back. | |
51 ~SelfDeletingCallback(); | |
Bernhard Bauer
2016/01/26 11:09:03
Methods come before members.
knn
2016/01/26 14:37:43
But this is a destructor and seems appropriate to
Bernhard Bauer
2016/01/27 14:24:01
The macro below technically defines a constructor,
knn
2016/01/28 11:43:25
Done.
| |
52 DISALLOW_COPY_AND_ASSIGN(SelfDeletingCallback); | |
53 }; | |
54 | |
55 } // namespace android | |
56 | |
57 class ContentResolverWebRestrictionProvider : public WebRestrictionProvider { | |
Bernhard Bauer
2016/01/27 14:24:01
Why is this not in the android namespace, BTW?
knn
2016/01/28 11:43:25
web_restrictions is implicitly android at the mome
| |
58 public: | |
59 ContentResolverWebRestrictionProvider(); | |
60 ~ContentResolverWebRestrictionProvider() override; | |
61 | |
62 // Register JNI methods. | |
63 static bool Register(JNIEnv* env); | |
64 | |
65 // Verify the content provider and Setup. | |
Bernhard Bauer
2016/01/26 11:09:03
Does this method verify the setup (i.e. is "setup"
knn
2016/01/26 14:37:44
Done.
| |
66 void Initialize(const std::string& content_provider_authority); | |
67 | |
68 // WebRestrictionProvider: | |
69 UrlAccess ShouldProceed(bool is_main_frame, | |
70 const GURL& url, | |
71 const base::Callback<void(bool)>& callback) override; | |
72 | |
73 bool SupportsRequest() const override; | |
74 | |
75 bool GetErrorHtml(const GURL& url, std::string* error_html) const override; | |
Bernhard Bauer
2016/01/26 11:09:03
Identifying the error page by its URL isn't partic
knn
2016/01/26 14:37:44
That is the only information available to the prov
| |
76 | |
77 void RequestPermission(const GURL& url, | |
78 const base::Callback<void(bool)>& callback) override; | |
79 | |
80 private: | |
81 friend class android::SelfDeletingCallback; // For updating the cache. | |
82 | |
83 bool initialized_; | |
84 // Setup during Initialize. | |
Bernhard Bauer
2016/01/26 11:09:03
Also, "Set up [...]".
knn
2016/01/26 14:37:43
Done.
| |
85 bool supports_request_; | |
86 base::android::ScopedJavaGlobalRef<jobject> java_provider_; | |
87 | |
88 std::map<GURL, std::string> error_page_cache_; | |
89 std::map<GURL, bool> url_access_cache_; | |
Bernhard Bauer
2016/01/26 11:09:03
How are we dealing with cache invalidation here? A
knn
2016/01/26 14:37:43
We aren't. I was banking on a webview app's lifeti
Bernhard Bauer
2016/01/27 14:24:01
Hm, I could see various instances where that isn't
knn
2016/01/28 11:43:25
Clearing the cache on update now. Hope the cache h
| |
90 std::list<GURL> recent_urls_; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(ContentResolverWebRestrictionProvider); | |
93 }; | |
94 | |
95 } // namespace web_restriction | |
96 | |
97 #endif // COMPONENTS_WEB_RESTRICTION_CONTENT_RESOLVER_WEB_RESTRICTION_PROVIDER_ H_ | |
OLD | NEW |