Skip to content

Commit 05f0797

Browse files
authored
browser(firefox): support blob downloads (#1945)
1 parent 2637805 commit 05f0797

File tree

2 files changed

+24
-59
lines changed

2 files changed

+24
-59
lines changed

browser_patches/firefox/BUILD_NUMBER

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1085
1+
1086

browser_patches/firefox/patches/bootstrap.diff

Lines changed: 23 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ index 25c5b01fc54c8d45da8ceb7cf6ba163bee3c5361..490c5ce49cd9b5f804df59abbfb0450f
12791279
void internalResyncICUDefaultTimeZone();
12801280
diff --git a/juggler/Helper.js b/juggler/Helper.js
12811281
new file mode 100644
1282-
index 0000000000000000000000000000000000000000..b8e6649fb91be6cd72b000426fb4d58216745c4f
1282+
index 0000000000000000000000000000000000000000..2b1fe7fa712ae210af3ebbccda08404183d19921
12831283
--- /dev/null
12841284
+++ b/juggler/Helper.js
12851285
@@ -0,0 +1,115 @@
@@ -1326,15 +1326,15 @@ index 0000000000000000000000000000000000000000..b8e6649fb91be6cd72b000426fb4d582
13261326
+ return string.substring(1, string.length - 1);
13271327
+ }
13281328
+
1329-
+ getLoadContext(httpChannel) {
1329+
+ getLoadContext(channel) {
13301330
+ let loadContext = null;
13311331
+ try {
1332-
+ if (httpChannel.notificationCallbacks)
1333-
+ loadContext = httpChannel.notificationCallbacks.getInterface(Ci.nsILoadContext);
1332+
+ if (channel.notificationCallbacks)
1333+
+ loadContext = channel.notificationCallbacks.getInterface(Ci.nsILoadContext);
13341334
+ } catch (e) {}
13351335
+ try {
1336-
+ if (!loadContext && httpChannel.loadGroup)
1337-
+ loadContext = httpChannel.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext);
1336+
+ if (!loadContext && channel.loadGroup)
1337+
+ loadContext = channel.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext);
13381338
+ } catch (e) { }
13391339
+ return loadContext;
13401340
+ }
@@ -2336,10 +2336,10 @@ index 0000000000000000000000000000000000000000..ba34976ad05e7f5f1a99777f76ac08b1
23362336
+this.SimpleChannel = SimpleChannel;
23372337
diff --git a/juggler/TargetRegistry.js b/juggler/TargetRegistry.js
23382338
new file mode 100644
2339-
index 0000000000000000000000000000000000000000..5f10371dc2f2a921cd5df2b9b038bd1a6cec2533
2339+
index 0000000000000000000000000000000000000000..2e0c24790272fb398aae701b6b96c1d2d378c952
23402340
--- /dev/null
23412341
+++ b/juggler/TargetRegistry.js
2342-
@@ -0,0 +1,664 @@
2342+
@@ -0,0 +1,628 @@
23432343
+const {EventEmitter} = ChromeUtils.import('resource://gre/modules/EventEmitter.jsm');
23442344
+const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');
23452345
+const {SimpleChannel} = ChromeUtils.import('chrome://juggler/content/SimpleChannel.js');
@@ -2353,10 +2353,6 @@ index 0000000000000000000000000000000000000000..5f10371dc2f2a921cd5df2b9b038bd1a
23532353
+const {AccessibilityHandler} = ChromeUtils.import("chrome://juggler/content/protocol/AccessibilityHandler.js");
23542354
+const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
23552355
+
2356-
+const Cc = Components.classes;
2357-
+const Ci = Components.interfaces;
2358-
+const Cu = Components.utils;
2359-
+
23602356
+const helper = new Helper();
23612357
+
23622358
+const IDENTITY_NAME = 'JUGGLER ';
@@ -2371,40 +2367,21 @@ index 0000000000000000000000000000000000000000..5f10371dc2f2a921cd5df2b9b038bd1a
23712367
+ constructor(registry) {
23722368
+ this._registry = registry
23732369
+ this._handlerToUuid = new Map();
2374-
+ helper.addObserver(this._onRequest.bind(this), 'http-on-modify-request');
2375-
+ }
2376-
+
2377-
+ _onRequest(httpChannel, topic) {
2378-
+ let loadContext = helper.getLoadContext(httpChannel);
2379-
+ if (!loadContext)
2380-
+ return;
2381-
+ if (!loadContext.topFrameElement)
2382-
+ return;
2383-
+ const target = this._registry.targetForBrowser(loadContext.topFrameElement);
2384-
+ if (!target)
2385-
+ return;
2386-
+ target._httpChannelIds.add(httpChannel.channelId);
23872370
+ }
23882371
+
23892372
+ //
23902373
+ // nsIDownloadInterceptor implementation.
23912374
+ //
2392-
+ interceptDownloadRequest(externalAppHandler, request, outFile) {
2393-
+ const httpChannel = request.QueryInterface(Ci.nsIHttpChannel);
2394-
+ if (!httpChannel)
2395-
+ return false;
2396-
+ if (!httpChannel.loadInfo)
2375+
+ interceptDownloadRequest(externalAppHandler, request, browsingContext, outFile) {
2376+
+ const pageTarget = this._registry._browserBrowsingContextToTarget.get(browsingContext);
2377+
+ if (!pageTarget)
23972378
+ return false;
2398-
+ const userContextId = httpChannel.loadInfo.originAttributes.userContextId;
2399-
+ const browserContext = this._registry._userContextIdToBrowserContext.get(userContextId);
2379+
+
2380+
+ const browserContext = pageTarget.browserContext();
24002381
+ const options = browserContext.options.downloadOptions;
24012382
+ if (!options)
24022383
+ return false;
24032384
+
2404-
+ const pageTarget = this._registry._targetForChannel(httpChannel);
2405-
+ if (!pageTarget)
2406-
+ return false;
2407-
+
24082385
+ const uuid = helper.generateId();
24092386
+ let file = null;
24102387
+ if (options.behavior === 'saveToDisk') {
@@ -2425,7 +2402,7 @@ index 0000000000000000000000000000000000000000..5f10371dc2f2a921cd5df2b9b038bd1a
24252402
+ uuid,
24262403
+ browserContextId: browserContext.browserContextId,
24272404
+ pageTargetId: pageTarget.id(),
2428-
+ url: httpChannel.URI.spec,
2405+
+ url: request.name,
24292406
+ suggestedFileName: externalAppHandler.suggestedFileName,
24302407
+ };
24312408
+ this._registry.emit(TargetRegistry.Events.DownloadCreated, downloadInfo);
@@ -2649,18 +2626,6 @@ index 0000000000000000000000000000000000000000..5f10371dc2f2a921cd5df2b9b038bd1a
26492626
+ targetForBrowser(browser) {
26502627
+ return this._browserToTarget.get(browser);
26512628
+ }
2652-
+
2653-
+ _targetForChannel(httpChannel) {
2654-
+ let loadContext = helper.getLoadContext(httpChannel);
2655-
+ if (loadContext)
2656-
+ return this.targetForBrowser(loadContext.topFrameElement);
2657-
+ const channelId = httpChannel.channelId;
2658-
+ for (const target of this._browserToTarget.values()) {
2659-
+ if (target._httpChannelIds.has(channelId))
2660-
+ return target;
2661-
+ }
2662-
+ return null;
2663-
+ }
26642629
+}
26652630
+
26662631
+class PageTarget {
@@ -2676,7 +2641,6 @@ index 0000000000000000000000000000000000000000..5f10371dc2f2a921cd5df2b9b038bd1a
26762641
+ this._url = '';
26772642
+ this._openerId = opener ? opener.id() : undefined;
26782643
+ this._channel = SimpleChannel.createForMessageManager(`browser::page[${this._targetId}]`, this._linkedBrowser.messageManager);
2679-
+ this._httpChannelIds = new Set();
26802644
+
26812645
+ const navigationListener = {
26822646
+ QueryInterface: ChromeUtils.generateQI([ Ci.nsIWebProgressListener]),
@@ -7797,7 +7761,7 @@ index 87701f8d2cfee8bd84acd28c62b3be4989c9474c..ae1aa85c019cb21d4f7e79c35e8afe72
77977761
+ [optional] in unsigned long aFlags);
77987762
};
77997763
diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp
7800-
index 3c6d29151a3271638b2f9af2fff9641d353989d4..67edf27465a407da9097cf7cf17f41c35c61a534 100644
7764+
index 3c6d29151a3271638b2f9af2fff9641d353989d4..94dddbfb401f0d876c5bbf1ae4de90bdc23db835 100644
78017765
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
78027766
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
78037767
@@ -99,6 +99,7 @@
@@ -7843,7 +7807,7 @@ index 3c6d29151a3271638b2f9af2fff9641d353989d4..67edf27465a407da9097cf7cf17f41c3
78437807
+ nsCOMPtr<nsIDownloadInterceptor> interceptor = mExtProtSvc->mInterceptor;
78447808
+ if (interceptor) {
78457809
+ nsCOMPtr<nsIFile> fileToUse;
7846-
+ rv = interceptor->InterceptDownloadRequest(this, request, getter_AddRefs(fileToUse), &isIntercepted);
7810+
+ rv = interceptor->InterceptDownloadRequest(this, request, mBrowsingContext, getter_AddRefs(fileToUse), &isIntercepted);
78477811
+ if (!NS_SUCCEEDED(rv)) {
78487812
+ LOG((" failed to call nsIDowloadInterceptor.interceptDownloadRequest"));
78497813
+ return rv;
@@ -7939,18 +7903,19 @@ index 288676c354cfc571ad5eff01dd2db5232c084394..249326acca0685cbacefa74f712a2415
79397903
* When we download a helper app, we are going to retarget all load
79407904
* notifications into our own docloader and load group instead of
79417905
diff --git a/uriloader/exthandler/nsIExternalHelperAppService.idl b/uriloader/exthandler/nsIExternalHelperAppService.idl
7942-
index 8a55c1bd666c4f7a032863f1527a2315830643c5..c8bfff858079216798e0c71cc757e67466ad4ce1 100644
7906+
index 8a55c1bd666c4f7a032863f1527a2315830643c5..f7891682bd1903e45f96bd081f5af5a20a098edd 100644
79437907
--- a/uriloader/exthandler/nsIExternalHelperAppService.idl
79447908
+++ b/uriloader/exthandler/nsIExternalHelperAppService.idl
7945-
@@ -6,6 +6,7 @@
7909+
@@ -6,6 +6,8 @@
79467910

79477911
#include "nsICancelable.idl"
79487912

7913+
+webidl BrowsingContext;
79497914
+interface nsIHelperAppLauncher;
79507915
interface nsIURI;
79517916
interface nsIRequest;
79527917
interface nsIStreamListener;
7953-
@@ -20,6 +21,17 @@ webidl BrowsingContext;
7918+
@@ -20,6 +22,17 @@ webidl BrowsingContext;
79547919
class nsExternalAppHandler;
79557920
%}
79567921

@@ -7960,15 +7925,15 @@ index 8a55c1bd666c4f7a032863f1527a2315830643c5..c8bfff858079216798e0c71cc757e674
79607925
+[scriptable, uuid(9a20e9b0-75d0-11ea-bc55-0242ac130003)]
79617926
+interface nsIDownloadInterceptor : nsISupports
79627927
+{
7963-
+ bool interceptDownloadRequest(in nsIHelperAppLauncher aHandler, in nsIRequest aRequest, out nsIFile file);
7928+
+ bool interceptDownloadRequest(in nsIHelperAppLauncher aHandler, in nsIRequest aRequest, in BrowsingContext aBrowsingContext, out nsIFile file);
79647929
+
79657930
+ void onDownloadComplete(in nsIHelperAppLauncher aHandler, in ACString aErrorName);
79667931
+};
79677932
+
79687933
/**
79697934
* The external helper app service is used for finding and launching
79707935
* platform specific external applications for a given mime content type.
7971-
@@ -49,7 +61,7 @@ interface nsIExternalHelperAppService : nsISupports
7936+
@@ -49,7 +62,7 @@ interface nsIExternalHelperAppService : nsISupports
79727937
in nsIInterfaceRequestor aContentContext,
79737938
in boolean aForceSave,
79747939
[optional] in nsIInterfaceRequestor aWindowContext);
@@ -7977,7 +7942,7 @@ index 8a55c1bd666c4f7a032863f1527a2315830643c5..c8bfff858079216798e0c71cc757e674
79777942
/**
79787943
* Binds an external helper application to a stream listener. The caller
79797944
* should pump data into the returned stream listener. When the OnStopRequest
7980-
@@ -82,6 +94,7 @@ interface nsIExternalHelperAppService : nsISupports
7945+
@@ -82,6 +95,7 @@ interface nsIExternalHelperAppService : nsISupports
79817946
boolean applyDecodingForExtension(in AUTF8String aExtension,
79827947
in ACString aEncodingType);
79837948

0 commit comments

Comments
 (0)