-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'trunk' into py_dl_files
- Loading branch information
Showing
21 changed files
with
1,638 additions
and
634 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,69 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.bidi; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.function.Consumer; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.bidi.network.BeforeRequestSent; | ||
import org.openqa.selenium.internal.Require; | ||
|
||
public class Network implements AutoCloseable { | ||
|
||
private final Set<String> browsingContextIds; | ||
|
||
private final BiDi bidi; | ||
|
||
private final Event<BeforeRequestSent> beforeRequestSentEvent = | ||
new Event<>("network.beforeRequestSent", BeforeRequestSent::fromJsonMap); | ||
|
||
public Network(WebDriver driver) { | ||
this(new HashSet<>(), driver); | ||
} | ||
|
||
public Network(String browsingContextId, WebDriver driver) { | ||
this(Collections.singleton(Require.nonNull("Browsing context id", browsingContextId)), driver); | ||
} | ||
|
||
public Network(Set<String> browsingContextIds, WebDriver driver) { | ||
Require.nonNull("WebDriver", driver); | ||
Require.nonNull("Browsing context id list", browsingContextIds); | ||
|
||
if (!(driver instanceof HasBiDi)) { | ||
throw new IllegalArgumentException("WebDriver instance must support BiDi protocol"); | ||
} | ||
|
||
this.bidi = ((HasBiDi) driver).getBiDi(); | ||
this.browsingContextIds = browsingContextIds; | ||
} | ||
|
||
public void onBeforeRequestSent(Consumer<BeforeRequestSent> consumer) { | ||
if (browsingContextIds.isEmpty()) { | ||
this.bidi.addListener(beforeRequestSentEvent, consumer); | ||
} else { | ||
this.bidi.addListener(browsingContextIds, beforeRequestSentEvent, consumer); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
this.bidi.clearListener(beforeRequestSentEvent); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
java/src/org/openqa/selenium/bidi/network/AuthChallenge.java
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,62 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.bidi.network; | ||
|
||
import org.openqa.selenium.json.JsonInput; | ||
|
||
public class AuthChallenge { | ||
|
||
private final String scheme; | ||
private final String realm; | ||
|
||
private AuthChallenge(String scheme, String realm) { | ||
this.scheme = scheme; | ||
this.realm = realm; | ||
} | ||
|
||
public static AuthChallenge fromJson(JsonInput input) { | ||
String scheme = null; | ||
String realm = null; | ||
|
||
input.beginObject(); | ||
while (input.hasNext()) { | ||
switch (input.nextName()) { | ||
case "scheme": | ||
scheme = input.read(String.class); | ||
break; | ||
case "realm": | ||
realm = input.read(String.class); | ||
break; | ||
default: | ||
input.skipValue(); | ||
} | ||
} | ||
|
||
input.endObject(); | ||
|
||
return new AuthChallenge(scheme, realm); | ||
} | ||
|
||
public String getScheme() { | ||
return scheme; | ||
} | ||
|
||
public String getRealm() { | ||
return realm; | ||
} | ||
} |
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
Oops, something went wrong.