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

Side by Side Diff: components/web_restriction/content_resolver_web_restriction_provider.cc

Issue 1423713015: [WIP] WebRestrictions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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 unified diff | Download patch
OLDNEW
(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 #include "components/web_restriction/content_resolver_web_restriction_provider.h "
6
7 #include "base/android/jni_string.h"
8 #include "base/android/scoped_java_ref.h"
9 #include "jni/ContentResolverWebRestrictionProvider_jni.h"
10
11 namespace web_restriction {
12 namespace android {
13
14 SelfDeletingCallback::SelfDeletingCallback(
15 const GURL& url,
16 const base::Callback<void(bool)>& callback)
17 : url_(url), callback_(callback) {}
18
19 SelfDeletingCallback::~SelfDeletingCallback() {}
20
21 void SelfDeletingCallback::ShouldProceed(
22 JNIEnv* env,
23 const base::android::JavaParamRef<jobject>& obj,
24 jboolean should_proceed) {
25 // TODO Update cache
Bernhard Bauer 2016/01/22 17:32:31 What cache?
knn 2016/01/25 11:54:24 Cache of known statuses.
26 callback_.Run(should_proceed);
27 delete this;
28 }
29
30 } // namespace android
31
32 ContentResolverWebRestrictionProvider::ContentResolverWebRestrictionProvider() {
33 initialized_ = false;
34 }
35
36 ContentResolverWebRestrictionProvider::
37 ~ContentResolverWebRestrictionProvider() {}
38
39 // static
40 bool ContentResolverWebRestrictionProvider::Register(JNIEnv* env) {
41 return android::RegisterNativesImpl(env);
42 }
43
44 void ContentResolverWebRestrictionProvider::Initialize(
45 const std::string& content_provider_authority) {
46 DCHECK(!initialized_);
47 DCHECK(!content_provider_authority.empty());
48 // TODO Check if valid authority
49 initialized_ = true;
50 JNIEnv* env = base::android::AttachCurrentThread();
51 java_provider_.Reset(
52 android::Java_ContentResolverWebRestrictionProvider_create(
53 env, base::android::ConvertUTF8ToJavaString(
54 env, content_provider_authority)
55 .obj()));
56 supports_request_ =
57 android::Java_ContentResolverWebRestrictionProvider_supportsRequest(
58 env, java_provider_.obj());
59 ScopedJavaLocalRef<jstring> j_error_page =
60 android::Java_ContentResolverWebRestrictionProvider_getErrorPage(
aberent 2016/01/21 12:00:43 The error page isn't set until there is a response
knn 2016/01/21 12:17:22 My bad.
61 env, java_provider_.obj());
62 if (!j_error_page.is_null()) {
63 error_page_ = base::android::ConvertJavaStringToUTF8(j_error_page);
64 } else {
65 error_page_ = "";
Bernhard Bauer 2016/01/22 17:32:31 .clear()
knn 2016/01/25 11:54:24 Done.
66 }
67 }
68
69 UrlAccess ContentResolverWebRestrictionProvider::ShouldProceed(
70 bool is_main_frame,
71 const GURL& url) const {
72 if (!initialized_)
73 return ALLOW;
74 // TODO: Implement Cache here.
75 return UNKNOWN;
76 }
77
78 void ContentResolverWebRestrictionProvider::ShouldProceed(
79 bool is_main_frame,
80 const GURL& url,
81 const base::Callback<void(bool)>& callback) const {
82 // This should only be called after hitting the cache first.
83 DCHECK(initialized_);
84 // This will delete itself on being called.
85 android::SelfDeletingCallback* wrapped_callback =
86 new android::SelfDeletingCallback(url, callback);
87 JNIEnv* env = base::android::AttachCurrentThread();
88 android::Java_ContentResolverWebRestrictionProvider_shouldProceed(
89 env, java_provider_.obj(), reinterpret_cast<jlong>(wrapped_callback),
90 base::android::ConvertUTF8ToJavaString(env, url.spec()).obj());
91 }
92
93 bool ContentResolverWebRestrictionProvider::SupportsRequest() const {
94 return supports_request_;
95 }
96
97 bool ContentResolverWebRestrictionProvider::SupportsCustomErrorPage() const {
98 return !error_page_.empty();
99 }
100
101 std::string ContentResolverWebRestrictionProvider::GetErrorHtml() const {
102 DCHECK(SupportsCustomErrorPage());
103 return error_page_;
104 }
105
106 void ContentResolverWebRestrictionProvider::RequestPermission(const GURL& url) {
107 // Throttling should be implemented by the Content Provider?
108 JNIEnv* env = base::android::AttachCurrentThread();
109 android::Java_ContentResolverWebRestrictionProvider_requestPermission(
110 env, java_provider_.obj(),
111 base::android::ConvertUTF8ToJavaString(env, url.spec()).obj());
112 }
113
114 void ContentResolverWebRestrictionProvider::AddObserver(Observer* observer) {}
115
116 void ContentResolverWebRestrictionProvider::RemoveObserver(Observer* observer) {
117 }
118
119 } // namespace web_restriction
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698