Path: blob/trunk/javascript/selenium-webdriver/bidi/realmInfo.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617/**18* Represents the types of realms.19* Described in https://w3c.github.io/webdriver-bidi/#type-script-RealmType.20* @enum21*/22const RealmType = {23AUDIO_WORKLET: 'audio-worklet',24DEDICATED_WORKER: 'dedicated-worker',25PAINT_WORKLET: 'paint-worklet',26SERVICE_WORKED: 'service-worker',27SHARED_WORKED: 'shared-worker',28WINDOW: 'window',29WORKER: 'worker',30WORKLET: 'worklet',3132findByName(name) {33return (34Object.values(this).find((type) => {35return typeof type === 'string' && name.toLowerCase() === type.toLowerCase()36}) || null37)38},39}4041/**42* Represents information about a realm.43* Described in https://w3c.github.io/webdriver-bidi/#type-script-RealmInfo.44*/45class RealmInfo {46/**47* Constructs a new RealmInfo object.48* @param {string} realmId - The ID of the realm.49* @param {string} origin - The origin of the realm.50* @param {string} realmType - The type of the realm.51*/52constructor(realmId, origin, realmType) {53this.realmId = realmId54this.origin = origin55this.realmType = realmType56}5758static fromJson(input) {59let realmId = null60let origin = null61let realmType = null62let browsingContext = null63let sandbox = null6465if ('type' in input) {66let typeString = input['type']67realmType = RealmType.findByName(typeString)68}6970if ('realm' in input) {71realmId = input['realm']72}7374if ('origin' in input) {75origin = input['origin']76}7778if ('context' in input) {79browsingContext = input['context']80}8182if ('sandbox' in input) {83sandbox = input['sandbox']84}8586if (realmType === RealmType.WINDOW) {87return new WindowRealmInfo(realmId, origin, realmType, browsingContext, sandbox)88}8990return new RealmInfo(realmId, origin, realmType)91}92}9394/**95* Represents information about a window realm.96* @extends RealmInfo97*/98class WindowRealmInfo extends RealmInfo {99/**100* Constructs a new instance of the WindowRealmInfo class.101* @param {string} realmId - The ID of the realm.102* @param {string} origin - The origin of the realm.103* @param {string} realmType - The type of the realm.104* @param {string} browsingContext - The browsing context of the realm.105* @param {string|null} sandbox - The sandbox of the realm (optional).106*/107constructor(realmId, origin, realmType, browsingContext, sandbox = null) {108super(realmId, origin, realmType)109this.browsingContext = browsingContext110this.sandbox = sandbox111}112}113114module.exports = {115RealmInfo,116RealmType,117WindowRealmInfo,118}119120121