Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browser(firefox): support BrowserContext.setExtraHTTPHeaders #1111

Merged
merged 1 commit into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion browser_patches/firefox/BUILD_NUMBER
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1030
1031
93 changes: 59 additions & 34 deletions browser_patches/firefox/patches/bootstrap.diff
Original file line number Diff line number Diff line change
Expand Up @@ -763,17 +763,19 @@ index 0000000000000000000000000000000000000000..862c680198bbb503a5f04c19bdb8fdf2
+
diff --git a/testing/juggler/NetworkObserver.js b/testing/juggler/NetworkObserver.js
new file mode 100644
index 0000000000000000000000000000000000000000..66f61d432f9ad2f50931b780ec5ea0e33da53803
index 0000000000000000000000000000000000000000..8fe6a596bda3f58e6f93ba943fbbc0819bf0fc01
--- /dev/null
+++ b/testing/juggler/NetworkObserver.js
@@ -0,0 +1,681 @@
@@ -0,0 +1,689 @@
+"use strict";
+
+const {EventEmitter} = ChromeUtils.import('resource://gre/modules/EventEmitter.jsm');
+const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');
+const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
+const {NetUtil} = ChromeUtils.import('resource://gre/modules/NetUtil.jsm');
+const {CommonUtils} = ChromeUtils.import("resource://services-common/utils.js");
+const {TargetRegistry} = ChromeUtils.import('chrome://juggler/content/TargetRegistry.js');
+const {BrowserContextManager} = ChromeUtils.import('chrome://juggler/content/BrowserContextManager.js');
+
+
+const Cc = Components.classes;
Expand Down Expand Up @@ -992,11 +994,10 @@ index 0000000000000000000000000000000000000000..66f61d432f9ad2f50931b780ec5ea0e3
+ new ResponseBodyListener(this, browser, httpChannel);
+ return;
+ }
+ const extraHeaders = this._extraHTTPHeaders.get(browser);
+ if (extraHeaders) {
+ for (const header of extraHeaders)
+ httpChannel.setRequestHeader(header.name, header.value, false /* merge */);
+ }
+ const browserContext = TargetRegistry.instance().browserContextForBrowser(browser);
+ if (browserContext)
+ this._appendExtraHTTPHeaders(httpChannel, browserContext.options.extraHTTPHeaders);
+ this._appendExtraHTTPHeaders(httpChannel, this._extraHTTPHeaders.get(browser));
+ const requestId = this._requestId(httpChannel);
+ const isRedirect = this._redirectMap.has(requestId);
+ const interceptors = this._browserInterceptors.get(browser);
Expand All @@ -1022,6 +1023,13 @@ index 0000000000000000000000000000000000000000..66f61d432f9ad2f50931b780ec5ea0e3
+ }
+ }
+
+ _appendExtraHTTPHeaders(httpChannel, headers) {
+ if (!headers)
+ return;
+ for (const header of headers)
+ httpChannel.setRequestHeader(header.name, header.value, false /* merge */);
+ }
+
+ _onIntercepted(httpChannel, interceptor) {
+ const browser = this._getBrowserForChannel(httpChannel);
+ if (!browser) {
Expand Down Expand Up @@ -1450,10 +1458,10 @@ index 0000000000000000000000000000000000000000..66f61d432f9ad2f50931b780ec5ea0e3
+this.NetworkObserver = NetworkObserver;
diff --git a/testing/juggler/TargetRegistry.js b/testing/juggler/TargetRegistry.js
new file mode 100644
index 0000000000000000000000000000000000000000..6a128959f9128a87cd3d46a5d906028ff500f9e0
index 0000000000000000000000000000000000000000..4de911fc5bc9c93b961b0e70474ddbe10e4af8c6
--- /dev/null
+++ b/testing/juggler/TargetRegistry.js
@@ -0,0 +1,232 @@
@@ -0,0 +1,239 @@
+const {EventEmitter} = ChromeUtils.import('resource://gre/modules/EventEmitter.jsm');
+const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');
+const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
Expand Down Expand Up @@ -1554,6 +1562,16 @@ index 0000000000000000000000000000000000000000..6a128959f9128a87cd3d46a5d906028f
+ return this._targets.get(targetId);
+ }
+
+ targetForBrowser(browser) {
+ const tab = this._mainWindow.gBrowser.getTabForBrowser(browser);
+ return tab ? this._tabToTarget.get(tab) : undefined;
+ }
+
+ browserContextForBrowser(browser) {
+ const tab = this._mainWindow.gBrowser.getTabForBrowser(browser);
+ return tab ? this._contextManager.browserContextForUserContextId(tab.userContextId) : undefined;
+ }
+
+ _createTargetForTab(tab) {
+ if (this._tabToTarget.has(tab))
+ throw new Error(`Internal error: two targets per tab`);
Expand All @@ -1570,10 +1588,7 @@ index 0000000000000000000000000000000000000000..6a128959f9128a87cd3d46a5d906028f
+ const browser = subject.ownerElement;
+ if (!browser)
+ return;
+ const tab = this._mainWindow.gBrowser.getTabForBrowser(browser);
+ if (!tab)
+ return;
+ const target = this._tabToTarget.get(tab);
+ const target = this.targetForBrowser(browser);
+ if (!target)
+ return;
+ this.emit(TargetRegistry.Events.TargetCrashed, target.id());
Expand Down Expand Up @@ -4117,10 +4132,10 @@ index 0000000000000000000000000000000000000000..a2d3b79469566ca2edb7d864621f7085
+this.AccessibilityHandler = AccessibilityHandler;
diff --git a/testing/juggler/protocol/BrowserHandler.js b/testing/juggler/protocol/BrowserHandler.js
new file mode 100644
index 0000000000000000000000000000000000000000..6b42032e8f6d39025f455300d376084826a781cc
index 0000000000000000000000000000000000000000..af071300faeb8018ec2e956743d0a619886248b8
--- /dev/null
+++ b/testing/juggler/protocol/BrowserHandler.js
@@ -0,0 +1,73 @@
@@ -0,0 +1,77 @@
+"use strict";
+
+const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
Expand Down Expand Up @@ -4166,6 +4181,10 @@ index 0000000000000000000000000000000000000000..6b42032e8f6d39025f455300d3760848
+ this._contextManager.browserContextForId(browserContextId).resetPermissions();
+ }
+
+ setExtraHTTPHeaders({browserContextId, headers}) {
+ this._contextManager.browserContextForId(browserContextId).options.extraHTTPHeaders = headers;
+ }
+
+ setCookies({browserContextId, cookies}) {
+ this._contextManager.browserContextForId(browserContextId).setCookies(cookies);
+ }
Expand Down Expand Up @@ -5060,10 +5079,10 @@ index 0000000000000000000000000000000000000000..78b6601b91d0b7fcda61114e6846aa07
+this.EXPORTED_SYMBOLS = ['t', 'checkScheme'];
diff --git a/testing/juggler/protocol/Protocol.js b/testing/juggler/protocol/Protocol.js
new file mode 100644
index 0000000000000000000000000000000000000000..6751bfaa84655952f4a51e3dd4353eb84f517fcb
index 0000000000000000000000000000000000000000..b6da790c65f25363a5bb85d7525bf2185d884235
--- /dev/null
+++ b/testing/juggler/protocol/Protocol.js
@@ -0,0 +1,752 @@
@@ -0,0 +1,758 @@
+const {t, checkScheme} = ChromeUtils.import('chrome://juggler/content/protocol/PrimitiveTypes.js');
+
+// Protocol-specific types.
Expand Down Expand Up @@ -5225,6 +5244,21 @@ index 0000000000000000000000000000000000000000..6751bfaa84655952f4a51e3dd4353eb8
+ foundObject: t.Optional(t.Boolean),
+}
+
+const networkTypes = {};
+
+networkTypes.HTTPHeader = {
+ name: t.String,
+ value: t.String,
+};
+
+networkTypes.SecurityDetails = {
+ protocol: t.String,
+ subjectName: t.String,
+ issuer: t.String,
+ validFrom: t.Number,
+ validTo: t.Number,
+};
+
+const Browser = {
+ targets: ['browser'],
+
Expand All @@ -5245,6 +5279,12 @@ index 0000000000000000000000000000000000000000..6751bfaa84655952f4a51e3dd4353eb8
+ enabled: t.Boolean,
+ },
+ },
+ 'setExtraHTTPHeaders': {
+ params: {
+ browserContextId: t.Optional(t.String),
+ headers: t.Array(networkTypes.HTTPHeader),
+ },
+ },
+ 'grantPermissions': {
+ params: {
+ origin: t.String,
Expand Down Expand Up @@ -5343,21 +5383,6 @@ index 0000000000000000000000000000000000000000..6751bfaa84655952f4a51e3dd4353eb8
+ },
+};
+
+const networkTypes = {};
+
+networkTypes.HTTPHeader = {
+ name: t.String,
+ value: t.String,
+};
+
+networkTypes.SecurityDetails = {
+ protocol: t.String,
+ subjectName: t.String,
+ issuer: t.String,
+ validFrom: t.Number,
+ validTo: t.Number,
+};
+
+const Network = {
+ targets: ['page'],
+ types: networkTypes,
Expand Down Expand Up @@ -5861,7 +5886,7 @@ index 0000000000000000000000000000000000000000..089e66c617f114fcb32b3cea20abc6fb
+this.RuntimeHandler = RuntimeHandler;
diff --git a/testing/juggler/protocol/TargetHandler.js b/testing/juggler/protocol/TargetHandler.js
new file mode 100644
index 0000000000000000000000000000000000000000..4795a4ddecdd016d6efbcde35aa7321af17cd7dc
index 0000000000000000000000000000000000000000..c0bab449971de13f993ac9825ac13368f8d8e226
--- /dev/null
+++ b/testing/juggler/protocol/TargetHandler.js
@@ -0,0 +1,100 @@
Expand Down Expand Up @@ -5935,7 +5960,7 @@ index 0000000000000000000000000000000000000000..4795a4ddecdd016d6efbcde35aa7321a
+ if (browserContext.options.removeOnDetach)
+ browserContext.destroy();
+ }
+ this._createdBrowserContextOptions.clear();
+ this._createdBrowserContextIds.clear();
+ }
+
+ _onTargetCreated(targetInfo) {
Expand Down