|
| 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.browsingcontext; |
| 19 | + |
| 20 | +import static java.util.Collections.unmodifiableMap; |
| 21 | + |
| 22 | +import java.util.Map; |
| 23 | +import java.util.TreeMap; |
| 24 | +import org.openqa.selenium.json.JsonInput; |
| 25 | + |
| 26 | +public class HistoryUpdated { |
| 27 | + |
| 28 | + private final String browsingContextId; |
| 29 | + |
| 30 | + private final int timestamp; |
| 31 | + |
| 32 | + private final String url; |
| 33 | + |
| 34 | + private HistoryUpdated(String browsingContextId, int timestamp, String url) { |
| 35 | + this.browsingContextId = browsingContextId; |
| 36 | + this.timestamp = timestamp; |
| 37 | + this.url = url; |
| 38 | + } |
| 39 | + |
| 40 | + public static HistoryUpdated fromJson(JsonInput input) { |
| 41 | + String browsingContextId = null; |
| 42 | + int timestamp = 0; |
| 43 | + String url = null; |
| 44 | + |
| 45 | + input.beginObject(); |
| 46 | + while (input.hasNext()) { |
| 47 | + switch (input.nextName()) { |
| 48 | + case "context": |
| 49 | + browsingContextId = input.read(String.class); |
| 50 | + break; |
| 51 | + |
| 52 | + case "timestamp": |
| 53 | + timestamp = input.read(int.class); |
| 54 | + break; |
| 55 | + |
| 56 | + case "url": |
| 57 | + url = input.read(String.class); |
| 58 | + break; |
| 59 | + |
| 60 | + default: |
| 61 | + input.skipValue(); |
| 62 | + break; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + input.endObject(); |
| 67 | + |
| 68 | + return new HistoryUpdated(browsingContextId, timestamp, url); |
| 69 | + } |
| 70 | + |
| 71 | + public String getBrowsingContextId() { |
| 72 | + return browsingContextId; |
| 73 | + } |
| 74 | + |
| 75 | + public int getTimestamp() { |
| 76 | + return timestamp; |
| 77 | + } |
| 78 | + |
| 79 | + public String getUrl() { |
| 80 | + return url; |
| 81 | + } |
| 82 | + |
| 83 | + private Map<String, Object> toJson() { |
| 84 | + Map<String, Object> toReturn = new TreeMap<>(); |
| 85 | + |
| 86 | + toReturn.put("browsingContextId", this.getBrowsingContextId()); |
| 87 | + toReturn.put("timestamp", this.getTimestamp()); |
| 88 | + toReturn.put("url", this.getUrl()); |
| 89 | + |
| 90 | + return unmodifiableMap(toReturn); |
| 91 | + } |
| 92 | +} |
0 commit comments