Skip to content

Commit 3dfef4a

Browse files
nitsakhJohn Kleinschmidt
authored andcommitted
chore: Add new webFrame IsolatedWorldInfo API and deprecate (electron#16801)
* chore: Add new webFrame IsolatedWorldInfo API and deprecate * Flag deprecated methods in documentation * address comments * Address review comments * remove unused variable * Update based on review
1 parent 1f458eb commit 3dfef4a

File tree

4 files changed

+72
-6
lines changed

4 files changed

+72
-6
lines changed

atom/renderer/api/atom_api_web_frame.cc

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,26 @@ void SetIsolatedWorldHumanReadableName(v8::Local<v8::Value> window,
399399
world_id, blink::WebString::FromUTF8(name));
400400
}
401401

402+
void SetIsolatedWorldInfo(v8::Local<v8::Value> window,
403+
int world_id,
404+
const mate::Dictionary& options,
405+
mate::Arguments* args) {
406+
std::string origin, csp, name;
407+
options.Get("securityOrigin", &origin);
408+
options.Get("csp", &csp);
409+
options.Get("name", &name);
410+
411+
if (!csp.empty() && origin.empty()) {
412+
args->ThrowError(
413+
"If csp is specified, securityOrigin should also be specified");
414+
return;
415+
}
416+
417+
SetIsolatedWorldSecurityOrigin(window, world_id, origin);
418+
SetIsolatedWorldContentSecurityPolicy(window, world_id, csp);
419+
SetIsolatedWorldHumanReadableName(window, world_id, name);
420+
}
421+
402422
blink::WebCache::ResourceTypeStats GetResourceUsage(v8::Isolate* isolate) {
403423
blink::WebCache::ResourceTypeStats stats;
404424
blink::WebCache::GetResourceTypeStats(&stats);
@@ -530,12 +550,13 @@ void Initialize(v8::Local<v8::Object> exports,
530550
dict.SetMethod("executeJavaScript", &ExecuteJavaScript);
531551
dict.SetMethod("executeJavaScriptInIsolatedWorld",
532552
&ExecuteJavaScriptInIsolatedWorld);
533-
dict.SetMethod("setIsolatedWorldSecurityOrigin",
553+
dict.SetMethod("_setIsolatedWorldSecurityOrigin",
534554
&SetIsolatedWorldSecurityOrigin);
535-
dict.SetMethod("setIsolatedWorldContentSecurityPolicy",
555+
dict.SetMethod("_setIsolatedWorldContentSecurityPolicy",
536556
&SetIsolatedWorldContentSecurityPolicy);
537-
dict.SetMethod("setIsolatedWorldHumanReadableName",
557+
dict.SetMethod("_setIsolatedWorldHumanReadableName",
538558
&SetIsolatedWorldHumanReadableName);
559+
dict.SetMethod("setIsolatedWorldInfo", &SetIsolatedWorldInfo);
539560
dict.SetMethod("getResourceUsage", &GetResourceUsage);
540561
dict.SetMethod("clearCache", &ClearCache);
541562
dict.SetMethod("_findFrameByRoutingId", &FindFrameByRoutingId);

docs/api/breaking-changes.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,23 @@ Child windows opened with the `nativeWindowOpen` option will always have Node.js
7171
Renderer process APIs `webFrame.setRegisterURLSchemeAsPrivileged` and `webFrame.registerURLSchemeAsBypassingCSP` as well as browser process API `protocol.registerStandardSchemes` have been removed.
7272
A new API, `protocol.registerSchemesAsPrivileged` has been added and should be used for registering custom schemes with the required privileges. Custom schemes are required to be registered before app ready.
7373

74+
## webFrame Isolated World APIs
75+
76+
```js
77+
// Deprecated
78+
webFrame.setIsolatedWorldContentSecurityPolicy(worldId, csp)
79+
webFrame.setIsolatedWorldHumanReadableName(worldId, name)
80+
webFrame.setIsolatedWorldSecurityOrigin(worldId, securityOrigin)
81+
// Replace with
82+
webFrame.setIsolatedWorldInfo(
83+
worldId,
84+
{
85+
securityOrigin: 'some_origin',
86+
name: 'human_readable_name',
87+
csp: 'content_security_policy'
88+
})
89+
```
90+
7491
# Planned Breaking API Changes (4.0)
7592

7693
The following list includes the breaking API changes made in Electron 4.0.

docs/api/web-frame.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,27 +127,37 @@ this limitation.
127127

128128
Work like `executeJavaScript` but evaluates `scripts` in an isolated context.
129129

130-
### `webFrame.setIsolatedWorldContentSecurityPolicy(worldId, csp)`
130+
### `webFrame.setIsolatedWorldContentSecurityPolicy(worldId, csp)` _(Deprecated)_
131131

132132
* `worldId` Integer - The ID of the world to run the javascript in, `0` is the default world, `999` is the world used by Electrons `contextIsolation` feature. You can provide any integer here.
133133
* `csp` String
134134

135135
Set the content security policy of the isolated world.
136136

137-
### `webFrame.setIsolatedWorldHumanReadableName(worldId, name)`
137+
### `webFrame.setIsolatedWorldHumanReadableName(worldId, name)` _(Deprecated)_
138138

139139
* `worldId` Integer - The ID of the world to run the javascript in, `0` is the default world, `999` is the world used by Electrons `contextIsolation` feature. You can provide any integer here.
140140
* `name` String
141141

142142
Set the name of the isolated world. Useful in devtools.
143143

144-
### `webFrame.setIsolatedWorldSecurityOrigin(worldId, securityOrigin)`
144+
### `webFrame.setIsolatedWorldSecurityOrigin(worldId, securityOrigin)` _(Deprecated)_
145145

146146
* `worldId` Integer - The ID of the world to run the javascript in, `0` is the default world, `999` is the world used by Electrons `contextIsolation` feature. You can provide any integer here.
147147
* `securityOrigin` String
148148

149149
Set the security origin of the isolated world.
150150

151+
### `webFrame.setIsolatedWorldInfo(worldId, info)`
152+
* `worldId` Integer - The ID of the world to run the javascript in, `0` is the default world, `999` is the world used by Electrons `contextIsolation` feature. You can provide any integer here.
153+
* `info` Object
154+
* `securityOrigin` String (optional) - Security origin for the isolated world.
155+
* `csp` String (optional) - Content Security Policy for the isolated world.
156+
* `name` String (optional) - Name for isolated world. Useful in devtools.
157+
158+
Set the security origin, content security policy and name of the isolated world.
159+
Note: If the `csp` is specified, then the `securityOrigin` also has to be specified.
160+
151161
### `webFrame.getResourceUsage()`
152162

153163
Returns `Object`:

lib/renderer/api/web-frame.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const { EventEmitter } = require('events')
44
const binding = process.atomBinding('web_frame')
5+
const { deprecate } = require('electron')
56

67
class WebFrame extends EventEmitter {
78
constructor (context) {
@@ -47,6 +48,23 @@ class WebFrame extends EventEmitter {
4748
get routingId () {
4849
return binding._getRoutingId(this.context)
4950
}
51+
52+
// Deprecations
53+
// TODO(nitsakh): Remove in 6.0
54+
setIsolatedWorldSecurityOrigin (worldId, securityOrigin) {
55+
deprecate.warn('webFrame.setIsolatedWorldSecurityOrigin', 'webFrame.setIsolatedWorldInfo')
56+
binding._setIsolatedWorldSecurityOrigin(this.context, worldId, securityOrigin)
57+
}
58+
59+
setIsolatedWorldContentSecurityPolicy (worldId, csp) {
60+
deprecate.warn('webFrame.setIsolatedWorldContentSecurityPolicy', 'webFrame.setIsolatedWorldInfo')
61+
binding._setIsolatedWorldContentSecurityPolicy(this.context, worldId, csp)
62+
}
63+
64+
setIsolatedWorldHumanReadableName (worldId, name) {
65+
deprecate.warn('webFrame.setIsolatedWorldHumanReadableName', 'webFrame.setIsolatedWorldInfo')
66+
binding._setIsolatedWorldHumanReadableName(this.context, worldId, name)
67+
}
5068
}
5169

5270
// Populate the methods.

0 commit comments

Comments
 (0)