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

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: Created 5 years, 1 month 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
26 callback_.Run(should_proceed);
27 delete this;
28 }
29
30 } // namespace android
31
32 ContentResolverWebRestrictionProvider::ContentResolverWebRestrictionProvider() {
33 }
34
35 ContentResolverWebRestrictionProvider::
36 ~ContentResolverWebRestrictionProvider() {}
37
38 // static
39 bool ContentResolverWebRestrictionProvider::Register(JNIEnv* env) {
40 return android::RegisterNativesImpl(env);
41 }
42
43 void ContentResolverWebRestrictionProvider::Initialize(
44 const std::string& content_provider_authority) {
45 DCHECK(!initialized_);
46 DCHECK(!content_provider_authority.empty());
47 // TODO Check if valid authority
48 initialized_ = true;
49 JNIEnv* env = base::android::AttachCurrentThread();
50 java_provider_.Reset(
51 android::Java_ContentResolverWebRestrictionProvider_create(
52 env, base::android::ConvertUTF8ToJavaString(
53 env, content_provider_authority)
54 .obj()));
55 supports_request_ =
56 android::Java_ContentResolverWebRestrictionProvider_supportsRequest(
57 env, java_provider_.obj());
58 ScopedJavaLocalRef<jstring> j_error_page =
59 android::Java_ContentResolverWebRestrictionProvider_getErrorPage(
60 env, java_provider_.obj());
61 if (!j_error_page.is_null())
62 error_page_ = base::android::ConvertJavaStringToUTF8(j_error_page);
63 }
64
65 UrlAccess ContentResolverWebRestrictionProvider::ShouldProceed(
66 bool is_main_frame,
67 const GURL& url) const {
68 if (!initialized_)
69 return ALLOW;
70 // TODO: Implement Cache here.
71 return UNKNOWN;
72 }
73
74 void ContentResolverWebRestrictionProvider::ShouldProceed(
75 bool is_main_frame,
76 const GURL& url,
77 const base::Callback<void(bool)>& callback) const {
78 // This should only be called after hitting the cache first.
79 DCHECK(initialized_);
80 // This will delete itself on being called.
81 android::SelfDeletingCallback* wrapped_callback =
82 new android::SelfDeletingCallback(url, callback);
83 JNIEnv* env = base::android::AttachCurrentThread();
84 android::Java_ContentResolverWebRestrictionProvider_shouldProceed(
85 env, java_provider_.obj(), reinterpret_cast<jlong>(wrapped_callback),
86 base::android::ConvertUTF8ToJavaString(env, url.spec()).obj());
87 }
88
89 bool ContentResolverWebRestrictionProvider::SupportsRequest() const {
90 return supports_request_;
91 }
92
93 bool ContentResolverWebRestrictionProvider::SupportsCustomErrorPage() const {
94 return !error_page_.empty();
95 }
96
97 std::string ContentResolverWebRestrictionProvider::GetErrorHtml() const {
98 DCHECK(SupportsCustomErrorPage());
99 return error_page_;
100 }
101
102 void ContentResolverWebRestrictionProvider::RequestPermission(const GURL& url) {
103 // Throttling should be implemented by the Content Provider?
104 JNIEnv* env = base::android::AttachCurrentThread();
105 android::Java_ContentResolverWebRestrictionProvider_requestPermission(
106 env, java_provider_.obj(),
107 base::android::ConvertUTF8ToJavaString(env, url.spec()).obj());
108 }
109
110 void ContentResolverWebRestrictionProvider::AddObserver(Observer* observer) {}
111
112 void ContentResolverWebRestrictionProvider::RemoveObserver(Observer* observer) {
113 }
114
115 } // namespace web_restriction
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698