1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
android_webview / browser / aw_contents_origin_matcher.h [blame]
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_ORIGIN_MATCHER_H_
#define ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_ORIGIN_MATCHER_H_
#include <memory>
#include <string>
#include <vector>
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
namespace url {
class Origin;
}
namespace js_injection {
class OriginMatcher;
}
namespace android_webview {
// Wrapper for a |js_incection::OriginMatcher| that allows locked updates
// to the match rules.
//
// Lifetime: WebView
class AwContentsOriginMatcher
: public base::RefCountedThreadSafe<AwContentsOriginMatcher> {
public:
AwContentsOriginMatcher();
bool MatchesOrigin(const url::Origin& origin);
// Returns the list of invalid rules.
// If there are bad rules, no update is performed
std::vector<std::string> UpdateRuleList(
const std::vector<std::string>& rules);
// Java bindings for the java exposed version of this class
jboolean MatchesOrigin(JNIEnv* env, std::string& jorigin);
base::android::ScopedJavaLocalRef<jobjectArray> UpdateRuleList(
JNIEnv* env,
const base::android::JavaParamRef<jobjectArray>& jrules);
// Use this method to perform native clean up
void Destroy(JNIEnv* env);
private:
friend class base::RefCountedThreadSafe<AwContentsOriginMatcher>;
~AwContentsOriginMatcher();
base::Lock lock_;
std::unique_ptr<js_injection::OriginMatcher> origin_matcher_;
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_ORIGIN_MATCHER_H_