Skip to content

Commit cce0385

Browse files
authored
[bidi] [js] Add storage module (#13684)
1 parent 83083c6 commit cce0385

File tree

7 files changed

+711
-9
lines changed

7 files changed

+711
-9
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
const { SameSite } = require('./networkTypes')
19+
20+
class CookieFilter {
21+
#map = new Map()
22+
23+
name(name) {
24+
this.#map.set('name', name)
25+
return this
26+
}
27+
28+
value(value) {
29+
this.#map.set('value', Object.fromEntries(value.asMap()))
30+
return this
31+
}
32+
33+
domain(domain) {
34+
this.#map.set('domain', domain)
35+
return this
36+
}
37+
38+
path(path) {
39+
this.#map.set('path', path)
40+
return this
41+
}
42+
43+
size(size) {
44+
this.#map.set('size', size)
45+
return this
46+
}
47+
48+
httpOnly(httpOnly) {
49+
this.#map.set('httpOnly', httpOnly)
50+
return this
51+
}
52+
53+
secure(secure) {
54+
this.#map.set('secure', secure)
55+
return this
56+
}
57+
58+
sameSite(sameSite) {
59+
if (!(sameSite instanceof SameSite)) {
60+
throw new Error(`Params must be a value in SameSite. Received:'${sameSite}'`)
61+
}
62+
this.#map.set('sameSite', sameSite)
63+
return this
64+
}
65+
66+
expiry(expiry) {
67+
this.#map.set('expiry', expiry)
68+
return this
69+
}
70+
71+
asMap() {
72+
return this.#map
73+
}
74+
}
75+
76+
module.exports = { CookieFilter }

javascript/node/selenium-webdriver/bidi/networkTypes.js

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,47 @@
1717

1818
const { NavigationInfo } = require('./browsingContextTypes')
1919

20+
const SameSite = {
21+
STRICT: 'strict',
22+
LAX: 'lax',
23+
NONE: 'none',
24+
25+
findByName(name) {
26+
return (
27+
Object.values(this).find((type) => {
28+
return typeof type === 'string' && name.toLowerCase() === type.toLowerCase()
29+
}) || null
30+
)
31+
},
32+
}
33+
34+
class BytesValue {
35+
static Type = {
36+
STRING: 'string',
37+
BASE64: 'base64',
38+
}
39+
40+
constructor(type, value) {
41+
this._type = type
42+
this._value = value
43+
}
44+
45+
get type() {
46+
return this._type
47+
}
48+
49+
get value() {
50+
return this._value
51+
}
52+
53+
asMap() {
54+
const map = new Map()
55+
map.set('type', this._type)
56+
map.set('value', this._value)
57+
return map
58+
}
59+
}
60+
2061
class Header {
2162
constructor(name, value, binaryValue) {
2263
this._name = name
@@ -38,10 +79,9 @@ class Header {
3879
}
3980

4081
class Cookie {
41-
constructor(name, value, binaryValue, domain, path, expires, size, httpOnly, secure, sameSite) {
82+
constructor(name, value, domain, path, size, httpOnly, secure, sameSite, expires) {
4283
this._name = name
4384
this._value = value
44-
this._binaryValue = binaryValue
4585
this._domain = domain
4686
this._path = path
4787
this._expires = expires
@@ -59,10 +99,6 @@ class Cookie {
5999
return this._value
60100
}
61101

62-
get binaryValue() {
63-
return this._binaryValue
64-
}
65-
66102
get domain() {
67103
return this._domain
68104
}
@@ -201,10 +237,9 @@ class RequestData {
201237
let secure = cookie.secure
202238
let sameSite = cookie.sameSite
203239
let value = 'value' in cookie ? cookie.value : null
204-
let binaryValue = 'binaryValue' in cookie ? cookie.binaryValue : null
205240
let expires = 'expires' in cookie ? cookie.expires : null
206241

207-
this._cookies.push(new Cookie(name, value, binaryValue, domain, path, expires, size, httpOnly, secure, sameSite))
242+
this._cookies.push(new Cookie(name, value, domain, path, size, httpOnly, secure, sameSite, expires))
208243
})
209244
this._headersSize = headersSize
210245
this._bodySize = bodySize
@@ -453,4 +488,4 @@ class ResponseStarted extends BaseParameters {
453488
}
454489
}
455490

456-
module.exports = { BeforeRequestSent, ResponseStarted, FetchError }
491+
module.exports = { BytesValue, Cookie, SameSite, BeforeRequestSent, ResponseStarted, FetchError }
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
class PartialCookie {
19+
#map = new Map()
20+
21+
constructor(name, value, domain) {
22+
this.#map.set('name', name)
23+
this.#map.set('value', Object.fromEntries(value.asMap()))
24+
this.#map.set('domain', domain)
25+
}
26+
27+
path(path) {
28+
this.#map.set('path', path)
29+
return this
30+
}
31+
32+
size(size) {
33+
this.#map.set('size', size)
34+
return this
35+
}
36+
37+
httpOnly(httpOnly) {
38+
this.#map.set('httpOnly', httpOnly)
39+
return this
40+
}
41+
42+
secure(secure) {
43+
this.#map.set('secure', secure)
44+
return this
45+
}
46+
47+
sameSite(sameSite) {
48+
this.#map.set('sameSite', sameSite)
49+
return this
50+
}
51+
52+
expiry(expiry) {
53+
this.#map.set('expiry', expiry)
54+
return this
55+
}
56+
57+
asMap() {
58+
return this.#map
59+
}
60+
}
61+
62+
module.exports = { PartialCookie }
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
Type = {
19+
CONTEXT: 'context',
20+
STORAGE_KEY: 'storageKey',
21+
}
22+
23+
class PartitionDescriptor {
24+
#type
25+
26+
constructor(type) {
27+
this.#type = type
28+
}
29+
}
30+
31+
class BrowsingContextPartitionDescriptor extends PartitionDescriptor {
32+
#context = null
33+
34+
constructor(context) {
35+
super(Type.CONTEXT)
36+
this.#context = context
37+
}
38+
39+
asMap() {
40+
const map = new Map()
41+
map.set('type', Type.CONTEXT)
42+
map.set('context', this.#context)
43+
return map
44+
}
45+
}
46+
47+
class StorageKeyPartitionDescriptor extends PartitionDescriptor {
48+
#map = new Map()
49+
50+
constructor() {
51+
super(Type.STORAGE_KEY)
52+
}
53+
54+
userContext(userContext) {
55+
this.#map.set('userContext', userContext)
56+
return this
57+
}
58+
59+
sourceOrigin(sourceOrigin) {
60+
this.#map.set('sourceOrigin', sourceOrigin)
61+
return this
62+
}
63+
64+
asMap() {
65+
return this.#map
66+
}
67+
}
68+
69+
module.exports = { BrowsingContextPartitionDescriptor, StorageKeyPartitionDescriptor }
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
class PartitionKey {
19+
#userContext
20+
#sourceOrigin
21+
22+
constructor(userContext, sourceOrigin) {
23+
this.#userContext = userContext
24+
this.#sourceOrigin = sourceOrigin
25+
}
26+
27+
get userContext() {
28+
return this.#userContext
29+
}
30+
31+
get sourceOrigin() {
32+
return this.#sourceOrigin
33+
}
34+
}
35+
36+
module.exports = { PartitionKey }

0 commit comments

Comments
 (0)