Skip to content

Commit edd2fee

Browse files
authored
browser(firefox): grant permissions to all origins (#1405)
1 parent 3960b17 commit edd2fee

File tree

2 files changed

+62
-26
lines changed

2 files changed

+62
-26
lines changed

browser_patches/firefox/BUILD_NUMBER

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1042
1+
1043

browser_patches/firefox/patches/bootstrap.diff

+61-25
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,10 @@ index 5de630a1db847a09651b310928bb7bc4d4f66f29..0268bc2bdfb3bfda2ef6e01a5dd24209
458458
nsCOMPtr<nsIPrincipal> principal =
459459
diff --git a/juggler/BrowserContextManager.js b/juggler/BrowserContextManager.js
460460
new file mode 100644
461-
index 0000000000000000000000000000000000000000..670ffa0bf10b3bdc98a732b740c41c217f0bc720
461+
index 0000000000000000000000000000000000000000..6c3d918022f0e8ff84083cb20266c97902cd04d4
462462
--- /dev/null
463463
+++ b/juggler/BrowserContextManager.js
464-
@@ -0,0 +1,199 @@
464+
@@ -0,0 +1,214 @@
465465
+"use strict";
466466
+
467467
+const {ContextualIdentityService} = ChromeUtils.import("resource://gre/modules/ContextualIdentityService.jsm");
@@ -541,6 +541,8 @@ index 0000000000000000000000000000000000000000..670ffa0bf10b3bdc98a732b740c41c21
541541
+ this.userContextId = identity.userContextId;
542542
+ }
543543
+ this._principals = [];
544+
+ // Maps origins to the permission lists.
545+
+ this._permissions = new Map();
544546
+ this._manager._browserContextIdToBrowserContext.set(this.browserContextId, this);
545547
+ this._manager._userContextIdToBrowserContext.set(this.userContextId, this);
546548
+ this.options = options || {};
@@ -562,13 +564,7 @@ index 0000000000000000000000000000000000000000..670ffa0bf10b3bdc98a732b740c41c21
562564
+ }
563565
+
564566
+ grantPermissions(origin, permissions) {
565-
+ const attrs = { userContextId: this.userContextId || undefined };
566-
+ const principal = Services.scriptSecurityManager.createContentPrincipal(NetUtil.newURI(origin), attrs);
567-
+ this._principals.push(principal);
568-
+ for (const permission of ALL_PERMISSIONS) {
569-
+ const action = permissions.includes(permission) ? Ci.nsIPermissionManager.ALLOW_ACTION : Ci.nsIPermissionManager.DENY_ACTION;
570-
+ Services.perms.addFromPrincipal(principal, permission, action, Ci.nsIPermissionManager.EXPIRE_NEVER, 0 /* expireTime */);
571-
+ }
567+
+ this._permissions.set(origin, permissions);
572568
+ }
573569
+
574570
+ resetPermissions() {
@@ -577,6 +573,25 @@ index 0000000000000000000000000000000000000000..670ffa0bf10b3bdc98a732b740c41c21
577573
+ Services.perms.removeFromPrincipal(principal, permission);
578574
+ }
579575
+ this._principals = [];
576+
+ this._permissions.clear();
577+
+ }
578+
+
579+
+ grantPermissionsToOrigin(url) {
580+
+ let origin = Array.from(this._permissions.keys()).find(key => url.startsWith(key));
581+
+ if (!origin)
582+
+ origin = '*';
583+
+
584+
+ const permissions = this._permissions.get(origin);
585+
+ if (!permissions)
586+
+ return;
587+
+
588+
+ const attrs = { userContextId: this.userContextId || undefined };
589+
+ const principal = Services.scriptSecurityManager.createContentPrincipal(NetUtil.newURI(url), attrs);
590+
+ this._principals.push(principal);
591+
+ for (const permission of ALL_PERMISSIONS) {
592+
+ const action = permissions.includes(permission) ? Ci.nsIPermissionManager.ALLOW_ACTION : Ci.nsIPermissionManager.DENY_ACTION;
593+
+ Services.perms.addFromPrincipal(principal, permission, action, Ci.nsIPermissionManager.EXPIRE_NEVER, 0 /* expireTime */);
594+
+ }
580595
+ }
581596
+
582597
+ setCookies(cookies) {
@@ -1612,10 +1627,10 @@ index 0000000000000000000000000000000000000000..ba34976ad05e7f5f1a99777f76ac08b1
16121627
+this.SimpleChannel = SimpleChannel;
16131628
diff --git a/juggler/TargetRegistry.js b/juggler/TargetRegistry.js
16141629
new file mode 100644
1615-
index 0000000000000000000000000000000000000000..98071c0e2c5429cfe8f29c390de3944f7f6e52a9
1630+
index 0000000000000000000000000000000000000000..eab73deee89cc7c8ab0a304f79126264de5c4f8e
16161631
--- /dev/null
16171632
+++ b/juggler/TargetRegistry.js
1618-
@@ -0,0 +1,250 @@
1633+
@@ -0,0 +1,264 @@
16191634
+const {EventEmitter} = ChromeUtils.import('resource://gre/modules/EventEmitter.jsm');
16201635
+const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');
16211636
+const {SimpleChannel} = ChromeUtils.import('chrome://juggler/content/SimpleChannel.js');
@@ -1673,11 +1688,10 @@ index 0000000000000000000000000000000000000000..98071c0e2c5429cfe8f29c390de3944f
16731688
+ Services.obs.addObserver(this, 'oop-frameloader-crashed');
16741689
+ }
16751690
+
1676-
+ async ensurePermissionsInContextPages(browserContextId, permissions) {
1691+
+ pageTargets(browserContextId) {
16771692
+ const browserContext = this._contextManager.browserContextForId(browserContextId);
16781693
+ const pageTargets = [...this._targets.values()].filter(target => target instanceof PageTarget);
1679-
+ const contextPages = pageTargets.filter(target => target._browserContext === browserContext);
1680-
+ await Promise.all(contextPages.map(page => page._channel.connect('').send('ensurePermissions', permissions).catch(e => void e)));
1694+
+ return pageTargets.filter(target => target._browserContext === browserContext);
16811695
+ }
16821696
+
16831697
+ async newPage({browserContextId}) {
@@ -1775,10 +1789,16 @@ index 0000000000000000000000000000000000000000..98071c0e2c5429cfe8f29c390de3944f
17751789
+ this._registry = registry;
17761790
+ this._tab = tab;
17771791
+ this._browserContext = browserContext;
1792+
+ this._url = '';
17781793
+ this._openerId = opener ? opener.id() : undefined;
17791794
+ this._channel = SimpleChannel.createForMessageManager(`browser::page[${this._targetId}]`, tab.linkedBrowser.messageManager);
17801795
+
1796+
+ const navigationListener = {
1797+
+ QueryInterface: ChromeUtils.generateQI([ Ci.nsIWebProgressListener]),
1798+
+ onLocationChange: (aWebProgress, aRequest, aLocation) => this._onNavigated(aLocation),
1799+
+ };
17811800
+ this._eventListeners = [
1801+
+ helper.addProgressListener(tab.linkedBrowser, navigationListener, Ci.nsIWebProgress.NOTIFY_LOCATION),
17821802
+ helper.addMessageListener(tab.linkedBrowser.messageManager, 'juggler:content-ready', {
17831803
+ receiveMessage: () => this._onContentReady()
17841804
+ }),
@@ -1839,6 +1859,15 @@ index 0000000000000000000000000000000000000000..98071c0e2c5429cfe8f29c390de3944f
18391859
+ };
18401860
+ }
18411861
+
1862+
+ _onNavigated(aLocation) {
1863+
+ this._url = aLocation.spec;
1864+
+ this._browserContext.grantPermissionsToOrigin(this._url);
1865+
+ }
1866+
+
1867+
+ async ensurePermissions(permissions) {
1868+
+ await this._channel.connect('').send('ensurePermissions', permissions).catch(e => void e);
1869+
+ }
1870+
+
18421871
+ dispose() {
18431872
+ helper.removeListeners(this._eventListeners);
18441873
+ }
@@ -4146,7 +4175,7 @@ index 0000000000000000000000000000000000000000..3a386425d3796d0a6786dea193b3402d
41464175
+
41474176
diff --git a/juggler/content/main.js b/juggler/content/main.js
41484177
new file mode 100644
4149-
index 0000000000000000000000000000000000000000..212f1c1a218efebe8685b019e79fb553db720453
4178+
index 0000000000000000000000000000000000000000..6ce6eff8dc8852d7fbbac907421de6de39d8ed0e
41504179
--- /dev/null
41514180
+++ b/juggler/content/main.js
41524181
@@ -0,0 +1,129 @@
@@ -4163,7 +4192,7 @@ index 0000000000000000000000000000000000000000..212f1c1a218efebe8685b019e79fb553
41634192
+ 'geo',
41644193
+ 'microphone',
41654194
+ 'camera',
4166-
+ 'desktop-notifications',
4195+
+ 'desktop-notification',
41674196
+];
41684197
+
41694198
+const scrollbarManager = new ScrollbarManager(docShell);
@@ -4360,10 +4389,10 @@ index 0000000000000000000000000000000000000000..2f2b7ca247f6b6dff396fb4b644654de
43604389
+this.AccessibilityHandler = AccessibilityHandler;
43614390
diff --git a/juggler/protocol/BrowserHandler.js b/juggler/protocol/BrowserHandler.js
43624391
new file mode 100644
4363-
index 0000000000000000000000000000000000000000..060174f997f4a607c9e6d7bf4e1e204f07fe86c7
4392+
index 0000000000000000000000000000000000000000..a5f050cd024dfdd3d7b1366600273744f82c5cbb
43644393
--- /dev/null
43654394
+++ b/juggler/protocol/BrowserHandler.js
4366-
@@ -0,0 +1,163 @@
4395+
@@ -0,0 +1,172 @@
43674396
+"use strict";
43684397
+
43694398
+const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
@@ -4481,8 +4510,17 @@ index 0000000000000000000000000000000000000000..060174f997f4a607c9e6d7bf4e1e204f
44814510
+ }
44824511
+
44834512
+ async grantPermissions({browserContextId, origin, permissions}) {
4484-
+ this._contextManager.browserContextForId(browserContextId).grantPermissions(origin, permissions);
4485-
+ await this._targetRegistry.ensurePermissionsInContextPages(browserContextId, permissions);
4513+
+ const browserContext = this._contextManager.browserContextForId(browserContextId);
4514+
+ browserContext.grantPermissions(origin, permissions);
4515+
+ const contextPages = this._targetRegistry.pageTargets(browserContextId);
4516+
+ const promises = [];
4517+
+ for (const page of contextPages) {
4518+
+ if (origin === '*' || page._url.startsWith(origin)) {
4519+
+ browserContext.grantPermissionsToOrigin(page._url);
4520+
+ promises.push(page.ensurePermissions(permissions));
4521+
+ }
4522+
+ }
4523+
+ await Promise.all(promises);
44864524
+ }
44874525
+
44884526
+ resetPermissions({browserContextId}) {
@@ -5398,10 +5436,10 @@ index 0000000000000000000000000000000000000000..78b6601b91d0b7fcda61114e6846aa07
53985436
+this.EXPORTED_SYMBOLS = ['t', 'checkScheme'];
53995437
diff --git a/juggler/protocol/Protocol.js b/juggler/protocol/Protocol.js
54005438
new file mode 100644
5401-
index 0000000000000000000000000000000000000000..9f7f4ce40454257ff83e8d39b278c1dbc1353991
5439+
index 0000000000000000000000000000000000000000..9b636b045df0737039d94b5a6efc8c4f004eb58a
54025440
--- /dev/null
54035441
+++ b/juggler/protocol/Protocol.js
5404-
@@ -0,0 +1,747 @@
5442+
@@ -0,0 +1,745 @@
54055443
+const {t, checkScheme} = ChromeUtils.import('chrome://juggler/content/protocol/PrimitiveTypes.js');
54065444
+
54075445
+// Protocol-specific types.
@@ -5662,9 +5700,7 @@ index 0000000000000000000000000000000000000000..9f7f4ce40454257ff83e8d39b278c1db
56625700
+ params: {
56635701
+ origin: t.String,
56645702
+ browserContextId: t.Optional(t.String),
5665-
+ permissions: t.Array(t.Enum([
5666-
+ 'geo', 'microphone', 'camera', 'desktop-notifications'
5667-
+ ])),
5703+
+ permissions: t.Array(t.String),
56685704
+ },
56695705
+ },
56705706
+ 'resetPermissions': {

0 commit comments

Comments
 (0)