Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3298)

Unified Diff: components/web_restriction/content_resolver_web_restriction_provider.h

Issue 1631603002: Web restrictions component only. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..b651e3225b14462876bac8c95bcd4240dccefea0
--- /dev/null
+++ b/components/web_restriction/content_resolver_web_restriction_provider.h
@@ -0,0 +1,97 @@
+// 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_restriction/web_restriction_provider.h"
+
+namespace web_restriction {
+
+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 {
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
+ 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();
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.
+ DISALLOW_COPY_AND_ASSIGN(SelfDeletingCallback);
+};
+
+} // namespace android
+
+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
+ public:
+ ContentResolverWebRestrictionProvider();
+ ~ContentResolverWebRestrictionProvider() override;
+
+ // Register JNI methods.
+ static bool Register(JNIEnv* env);
+
+ // 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.
+ 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;
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
+
+ void RequestPermission(const GURL& url,
+ const base::Callback<void(bool)>& callback) override;
+
+ private:
+ friend class android::SelfDeletingCallback; // For updating the cache.
+
+ bool initialized_;
+ // Setup during Initialize.
Bernhard Bauer 2016/01/26 11:09:03 Also, "Set up [...]".
knn 2016/01/26 14:37:43 Done.
+ bool supports_request_;
+ base::android::ScopedJavaGlobalRef<jobject> java_provider_;
+
+ std::map<GURL, std::string> error_page_cache_;
+ 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
+ std::list<GURL> recent_urls_;
+
+ DISALLOW_COPY_AND_ASSIGN(ContentResolverWebRestrictionProvider);
+};
+
+} // namespace web_restriction
+
+#endif // COMPONENTS_WEB_RESTRICTION_CONTENT_RESOLVER_WEB_RESTRICTION_PROVIDER_H_

Powered by Google App Engine
This is Rietveld 408576698