Skip to content

Commit 21b07d5

Browse files
Delta456cgoldbergdiemol
authored
[java][BiDi] implement web extensions (#15660)
* [java][BiDi] implement web extensions * cleanup * fix spotbug --------- Co-authored-by: Corey Goldberg <1113081+cgoldberg@users.noreply.github.com> Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
1 parent 0aa4ac1 commit 21b07d5

File tree

13 files changed

+377
-0
lines changed

13 files changed

+377
-0
lines changed

java/src/org/openqa/selenium/bidi/module/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ java_library(
2525
"//java/src/org/openqa/selenium/bidi/permissions",
2626
"//java/src/org/openqa/selenium/bidi/script",
2727
"//java/src/org/openqa/selenium/bidi/storage",
28+
"//java/src/org/openqa/selenium/bidi/webextension",
2829
"//java/src/org/openqa/selenium/json",
2930
"//java/src/org/openqa/selenium/remote/http",
3031
artifact("com.google.auto.service:auto-service-annotations"),
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
load("@rules_jvm_external//:defs.bzl", "artifact")
2+
load("//java:defs.bzl", "java_library")
3+
4+
java_library(
5+
name = "webextension",
6+
srcs = glob(
7+
[
8+
"*.java",
9+
],
10+
),
11+
visibility = [
12+
"//java/src/org/openqa/selenium/bidi:__subpackages__",
13+
"//java/src/org/openqa/selenium/firefox:__subpackages__",
14+
"//java/src/org/openqa/selenium/remote:__pkg__",
15+
"//java/test/org/openqa/selenium/bidi:__subpackages__",
16+
"//java/test/org/openqa/selenium/grid:__subpackages__",
17+
],
18+
deps = [
19+
"//java/src/org/openqa/selenium:core",
20+
"//java/src/org/openqa/selenium/bidi",
21+
"//java/src/org/openqa/selenium/json",
22+
"//java/src/org/openqa/selenium/remote/http",
23+
artifact("com.google.auto.service:auto-service-annotations"),
24+
],
25+
)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.webextension;
19+
20+
import java.util.Map;
21+
22+
public class ExtensionArchivePath extends ExtensionData {
23+
private final String path;
24+
25+
public ExtensionArchivePath(String path) {
26+
this.path = path;
27+
}
28+
29+
@Override
30+
public Map<String, Object> toMap() {
31+
String type = "archivePath";
32+
return Map.of("extensionData", Map.of("type", type, "path", path));
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.webextension;
19+
20+
import java.util.Map;
21+
22+
public class ExtensionBase64Encoded extends ExtensionData {
23+
private final String value;
24+
25+
public ExtensionBase64Encoded(String value) {
26+
this.value = value;
27+
}
28+
29+
@Override
30+
public Map<String, Object> toMap() {
31+
String type = "base64";
32+
return Map.of("extensionData", Map.of("type", type, "value", value));
33+
}
34+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.webextension;
19+
20+
import java.util.Map;
21+
22+
public abstract class ExtensionData {
23+
public abstract Map<String, Object> toMap();
24+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.webextension;
19+
20+
import java.util.Map;
21+
22+
public class ExtensionPath extends ExtensionData {
23+
private final String path;
24+
25+
public ExtensionPath(String path) {
26+
this.path = path;
27+
}
28+
29+
@Override
30+
public Map<String, Object> toMap() {
31+
String type = "path";
32+
return Map.of("extensionData", Map.of("type", type, "path", path));
33+
}
34+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.webextension;
19+
20+
public class InstallExtensionParameters {
21+
22+
private final ExtensionData extensionData;
23+
24+
public InstallExtensionParameters(ExtensionData extensionData) {
25+
this.extensionData = extensionData;
26+
}
27+
28+
public ExtensionData getExtensionData() {
29+
return extensionData;
30+
}
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.webextension;
19+
20+
import java.util.Map;
21+
22+
public class UninstallExtensionParameters {
23+
24+
public final Map<String, Object> extension;
25+
26+
public UninstallExtensionParameters(Map<String, Object> extension) {
27+
this.extension = extension;
28+
}
29+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.webextension;
19+
20+
import java.util.Map;
21+
import org.openqa.selenium.WebDriver;
22+
import org.openqa.selenium.bidi.BiDi;
23+
import org.openqa.selenium.bidi.Command;
24+
import org.openqa.selenium.bidi.HasBiDi;
25+
import org.openqa.selenium.internal.Require;
26+
27+
public class WebExtension {
28+
private final BiDi bidi;
29+
30+
public WebExtension(WebDriver driver) {
31+
Require.nonNull("WebDriver", driver);
32+
33+
if (!(driver instanceof HasBiDi)) {
34+
throw new IllegalArgumentException("WebDriver instance must support BiDi protocol");
35+
}
36+
37+
this.bidi = ((HasBiDi) driver).getBiDi();
38+
}
39+
40+
public Map<String, Object> install(InstallExtensionParameters parameters) {
41+
Require.nonNull("Install parameters", parameters);
42+
return bidi.send(
43+
new Command<>("webExtension.install", parameters.getExtensionData().toMap(), Map.class));
44+
}
45+
46+
public Map<String, Object> uninstall(UninstallExtensionParameters parameters) {
47+
Require.nonNull("Uninstall parameters", parameters);
48+
return bidi.send(new Command<>("webExtension.uninstall", parameters.extension, Map.class));
49+
}
50+
}

java/src/org/openqa/selenium/remote/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ java_export(
3434
"//java/src/org/openqa/selenium/bidi/permissions",
3535
"//java/src/org/openqa/selenium/bidi/script",
3636
"//java/src/org/openqa/selenium/bidi/storage",
37+
"//java/src/org/openqa/selenium/bidi/webextension",
3738
"//java/src/org/openqa/selenium/devtools",
3839
"//java/src/org/openqa/selenium/devtools:augmenter",
3940
"//java/src/org/openqa/selenium/os",

0 commit comments

Comments
 (0)