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

Side by Side Diff: components/web_restrictions/browser/web_restrictions_client.h

Issue 1684153002: Web restrictions component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use source_set for test_support Created 4 years, 10 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 #ifndef COMPONENTS_WEB_RESTRICTION_WEB_RESTRICTIONS_CLIENT_H_
6 #define COMPONENTS_WEB_RESTRICTION_WEB_RESTRICTIONS_CLIENT_H_
7
8 #include <jni.h>
9 #include <list>
10 #include <map>
11 #include <string>
12
13 #include "base/android/jni_android.h"
14 #include "base/callback.h"
15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/sequenced_task_runner.h"
18 #include "base/single_thread_task_runner.h"
19 #include "url/gurl.h"
20
21 namespace web_restrictions {
22
23 enum UrlAccess { ALLOW, DISALLOW, PENDING };
24
25 class WebRestrictionsClient {
26 public:
27 // An instance of this class is expected to live through the lifetime of a
28 // browser and uses raw pointers in callbacks.
29 // Any changes to the class, enable/disable/change should be done through the
30 // SetAuthority(...) method.
31 WebRestrictionsClient();
32 ~WebRestrictionsClient();
33
34 // Register JNI methods.
35 static bool Register(JNIEnv* env);
36
37 // Verify the content provider and query it for basic information like does it
38 // support handling requests. This should be called everytime the provider
39 // changes. An empty authority can be used to disable this class.
40 void SetAuthority(const std::string& content_provider_authority);
41
42 // WebRestrictionsProvider:
43 UrlAccess ShouldProceed(bool is_main_frame,
44 const GURL& url,
45 const base::Callback<void(bool)>& callback);
46
47 bool SupportsRequest() const;
48
49 bool GetErrorHtml(const GURL& url, std::string* error_html) const;
50
51 void RequestPermission(const GURL& url,
52 const base::Callback<void(bool)>& callback);
53
54 void OnWebRestrictionsChanged();
55
56 private:
57 struct ShouldProceedResult {
58 bool ok_to_proceed;
59 std::string error_page;
60 };
61
62 void RecordURLAccess(const GURL& url);
63
64 void UpdateCache(std::string provider_authority,
65 GURL url,
66 bool should_proceed,
67 std::string error_page);
68
69 void RequestSupportKnown(std::string provider_authority,
70 bool supports_request);
71
72 void ClearCache();
73
74 static ShouldProceedResult ShouldProceedTask(
75 const GURL& url,
76 const base::android::JavaRef<jobject>& java_provider);
77
78 void OnShouldProceedComplete(std::string provider_authority,
79 const GURL& url,
80 const base::Callback<void(bool)>& callback,
81 const ShouldProceedResult& result);
82
83 // Set up after SetAuthority().
84 bool initialized_;
85 bool supports_request_;
86 base::android::ScopedJavaGlobalRef<jobject> java_provider_;
87 std::string provider_authority_;
88
89 scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
90 scoped_refptr<base::SingleThreadTaskRunner> single_thread_task_runner_;
91
92 std::map<GURL, std::string> error_page_cache_;
93 std::map<GURL, bool> url_access_cache_;
94 std::list<GURL> recent_urls_;
95
96 DISALLOW_COPY_AND_ASSIGN(WebRestrictionsClient);
97 };
98
99 } // namespace web_restrictions
100
101 #endif // COMPONENTS_WEB_RESTRICTION_WEB_RESTRICTIONS_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698