chore: simplify handler result (#959)

This commit is contained in:
Yury Semikhatsky 2022-06-23 18:59:04 -07:00 committed by GitHub
parent 7e285ffe44
commit fdec32c650
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 7 deletions

View File

@ -481,10 +481,10 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
void handleRoute(RouteImpl route) {
Router.HandleResult handled = routes.handle(route);
if (handled != Router.HandleResult.NoMatchingHandler) {
if (handled == Router.HandleResult.FoundMatchingHandler) {
maybeDisableNetworkInterception();
}
if (handled != Router.HandleResult.Handled){
if (!route.isHandled()){
route.resume();
}
}

View File

@ -196,10 +196,10 @@ public class PageImpl extends ChannelOwner implements Page {
} else if ("route".equals(event)) {
RouteImpl route = connection.getExistingObject(params.getAsJsonObject("route").get("guid").getAsString());
Router.HandleResult handled = routes.handle(route);
if (handled != Router.HandleResult.NoMatchingHandler) {
if (handled == Router.HandleResult.FoundMatchingHandler) {
maybeDisableNetworkInterception();
}
if (handled != Router.HandleResult.Handled) {
if (!route.isHandled()) {
browserContext.handleRoute(route);
}
} else if ("video".equals(event)) {

View File

@ -71,19 +71,19 @@ class Router {
return routes.size();
}
enum HandleResult { NoMatchingHandler, MatchedHandlerButNotHandled, Handled }
enum HandleResult { NoMatchingHandler, FoundMatchingHandler}
HandleResult handle(RouteImpl route) {
HandleResult result = HandleResult.NoMatchingHandler;
for (Iterator<RouteInfo> it = routes.iterator(); it.hasNext();) {
RouteInfo info = it.next();
if (info.handle(route)) {
result = HandleResult.FoundMatchingHandler;
if (info.isDone()) {
it.remove();
}
if (route.isHandled()) {
return HandleResult.Handled;
break;
}
result = HandleResult.MatchedHandlerButNotHandled;
}
}
return result;