Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only show servo button for few websites (#632)
- Loading branch information
1 parent
a52d544
commit 189976e
Showing
4 changed files
with
85 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.mozilla.servo; | ||
|
||
import android.content.Context; | ||
import android.content.res.Resources; | ||
import android.util.Log; | ||
|
||
import java.util.Arrays; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Stream; | ||
|
||
public class ServoWhiteList { | ||
private final Pattern[] mRules; | ||
|
||
public ServoWhiteList(Context context) { | ||
Resources res = context.getResources(); | ||
Stream<String> rules = Stream.of(res.getStringArray(R.array.servo_white_list)); | ||
mRules = rules.map(Pattern::compile).toArray(Pattern[]::new); | ||
} | ||
|
||
public boolean isAllowed(String url) { | ||
return url != null && Stream.of(mRules).anyMatch(r -> r.matcher(url).matches()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string-array name="servo_white_list"> | ||
<!-- | ||
Matches: | ||
https://servo.org | ||
https://download.servo.org | ||
https://download.servo.org | ||
https://servo.org/ | ||
https://servo.org/ddd | ||
Doesn't match: | ||
https://.servo.org/ddd | ||
https://servo.orgd | ||
http://servo.org | ||
--> | ||
<item>https:\/\/(.+\.)?servo\.org(\/.*)?$</item> | ||
<!-- All examples hosted under threejs.org/examples/ --> | ||
<item>https:\/\/threejs\.org\/examples\/.*</item> | ||
</string-array> | ||
</resources> |