@@ -1279,7 +1279,7 @@ index 25c5b01fc54c8d45da8ceb7cf6ba163bee3c5361..490c5ce49cd9b5f804df59abbfb0450f
1279
1279
void internalResyncICUDefaultTimeZone();
1280
1280
diff --git a/juggler/Helper.js b/juggler/Helper.js
1281
1281
new file mode 100644
1282
- index 0000000000000000000000000000000000000000..b8e6649fb91be6cd72b000426fb4d58216745c4f
1282
+ index 0000000000000000000000000000000000000000..2b1fe7fa712ae210af3ebbccda08404183d19921
1283
1283
--- /dev/null
1284
1284
+++ b/juggler/Helper.js
1285
1285
@@ -0,0 +1,115 @@
@@ -1326,15 +1326,15 @@ index 0000000000000000000000000000000000000000..b8e6649fb91be6cd72b000426fb4d582
1326
1326
+ return string.substring(1, string.length - 1);
1327
1327
+ }
1328
1328
+
1329
- + getLoadContext(httpChannel ) {
1329
+ + getLoadContext(channel ) {
1330
1330
+ let loadContext = null;
1331
1331
+ try {
1332
- + if (httpChannel .notificationCallbacks)
1333
- + loadContext = httpChannel .notificationCallbacks.getInterface(Ci.nsILoadContext);
1332
+ + if (channel .notificationCallbacks)
1333
+ + loadContext = channel .notificationCallbacks.getInterface(Ci.nsILoadContext);
1334
1334
+ } catch (e) {}
1335
1335
+ 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);
1338
1338
+ } catch (e) { }
1339
1339
+ return loadContext;
1340
1340
+ }
@@ -2336,10 +2336,10 @@ index 0000000000000000000000000000000000000000..ba34976ad05e7f5f1a99777f76ac08b1
2336
2336
+ this.SimpleChannel = SimpleChannel;
2337
2337
diff --git a/juggler/TargetRegistry.js b/juggler/TargetRegistry.js
2338
2338
new file mode 100644
2339
- index 0000000000000000000000000000000000000000..5f10371dc2f2a921cd5df2b9b038bd1a6cec2533
2339
+ index 0000000000000000000000000000000000000000..2e0c24790272fb398aae701b6b96c1d2d378c952
2340
2340
--- /dev/null
2341
2341
+++ b/juggler/TargetRegistry.js
2342
- @@ -0,0 +1,664 @@
2342
+ @@ -0,0 +1,628 @@
2343
2343
+ const {EventEmitter} = ChromeUtils.import('resource://gre/modules/EventEmitter.jsm');
2344
2344
+ const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');
2345
2345
+ const {SimpleChannel} = ChromeUtils.import('chrome://juggler/content/SimpleChannel.js');
@@ -2353,10 +2353,6 @@ index 0000000000000000000000000000000000000000..5f10371dc2f2a921cd5df2b9b038bd1a
2353
2353
+ const {AccessibilityHandler} = ChromeUtils.import("chrome://juggler/content/protocol/AccessibilityHandler.js");
2354
2354
+ const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
2355
2355
+
2356
- + const Cc = Components.classes;
2357
- + const Ci = Components.interfaces;
2358
- + const Cu = Components.utils;
2359
- +
2360
2356
+ const helper = new Helper();
2361
2357
+
2362
2358
+ const IDENTITY_NAME = 'JUGGLER ';
@@ -2371,40 +2367,21 @@ index 0000000000000000000000000000000000000000..5f10371dc2f2a921cd5df2b9b038bd1a
2371
2367
+ constructor(registry) {
2372
2368
+ this._registry = registry
2373
2369
+ 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);
2387
2370
+ }
2388
2371
+
2389
2372
+ //
2390
2373
+ // nsIDownloadInterceptor implementation.
2391
2374
+ //
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)
2397
2378
+ return false;
2398
- + const userContextId = httpChannel.loadInfo.originAttributes.userContextId;
2399
- + const browserContext = this._registry._userContextIdToBrowserContext.get(userContextId );
2379
+ +
2380
+ + const browserContext = pageTarget.browserContext( );
2400
2381
+ const options = browserContext.options.downloadOptions;
2401
2382
+ if (!options)
2402
2383
+ return false;
2403
2384
+
2404
- + const pageTarget = this._registry._targetForChannel(httpChannel);
2405
- + if (!pageTarget)
2406
- + return false;
2407
- +
2408
2385
+ const uuid = helper.generateId();
2409
2386
+ let file = null;
2410
2387
+ if (options.behavior === 'saveToDisk') {
@@ -2425,7 +2402,7 @@ index 0000000000000000000000000000000000000000..5f10371dc2f2a921cd5df2b9b038bd1a
2425
2402
+ uuid,
2426
2403
+ browserContextId: browserContext.browserContextId,
2427
2404
+ pageTargetId: pageTarget.id(),
2428
- + url: httpChannel.URI.spec ,
2405
+ + url: request.name ,
2429
2406
+ suggestedFileName: externalAppHandler.suggestedFileName,
2430
2407
+ };
2431
2408
+ this._registry.emit(TargetRegistry.Events.DownloadCreated, downloadInfo);
@@ -2649,18 +2626,6 @@ index 0000000000000000000000000000000000000000..5f10371dc2f2a921cd5df2b9b038bd1a
2649
2626
+ targetForBrowser(browser) {
2650
2627
+ return this._browserToTarget.get(browser);
2651
2628
+ }
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
- + }
2664
2629
+ }
2665
2630
+
2666
2631
+ class PageTarget {
@@ -2676,7 +2641,6 @@ index 0000000000000000000000000000000000000000..5f10371dc2f2a921cd5df2b9b038bd1a
2676
2641
+ this._url = '';
2677
2642
+ this._openerId = opener ? opener.id() : undefined;
2678
2643
+ this._channel = SimpleChannel.createForMessageManager(`browser::page[${this._targetId}]`, this._linkedBrowser.messageManager);
2679
- + this._httpChannelIds = new Set();
2680
2644
+
2681
2645
+ const navigationListener = {
2682
2646
+ QueryInterface: ChromeUtils.generateQI([ Ci.nsIWebProgressListener]),
@@ -7797,7 +7761,7 @@ index 87701f8d2cfee8bd84acd28c62b3be4989c9474c..ae1aa85c019cb21d4f7e79c35e8afe72
7797
7761
+ [optional] in unsigned long aFlags);
7798
7762
};
7799
7763
diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp
7800
- index 3c6d29151a3271638b2f9af2fff9641d353989d4..67edf27465a407da9097cf7cf17f41c35c61a534 100644
7764
+ index 3c6d29151a3271638b2f9af2fff9641d353989d4..94dddbfb401f0d876c5bbf1ae4de90bdc23db835 100644
7801
7765
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
7802
7766
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
7803
7767
@@ -99,6 +99,7 @@
@@ -7843,7 +7807,7 @@ index 3c6d29151a3271638b2f9af2fff9641d353989d4..67edf27465a407da9097cf7cf17f41c3
7843
7807
+ nsCOMPtr<nsIDownloadInterceptor> interceptor = mExtProtSvc->mInterceptor;
7844
7808
+ if (interceptor) {
7845
7809
+ nsCOMPtr<nsIFile> fileToUse;
7846
- + rv = interceptor->InterceptDownloadRequest(this, request, getter_AddRefs(fileToUse), &isIntercepted);
7810
+ + rv = interceptor->InterceptDownloadRequest(this, request, mBrowsingContext, getter_AddRefs(fileToUse), &isIntercepted);
7847
7811
+ if (!NS_SUCCEEDED(rv)) {
7848
7812
+ LOG((" failed to call nsIDowloadInterceptor.interceptDownloadRequest"));
7849
7813
+ return rv;
@@ -7939,18 +7903,19 @@ index 288676c354cfc571ad5eff01dd2db5232c084394..249326acca0685cbacefa74f712a2415
7939
7903
* When we download a helper app, we are going to retarget all load
7940
7904
* notifications into our own docloader and load group instead of
7941
7905
diff --git a/uriloader/exthandler/nsIExternalHelperAppService.idl b/uriloader/exthandler/nsIExternalHelperAppService.idl
7942
- index 8a55c1bd666c4f7a032863f1527a2315830643c5..c8bfff858079216798e0c71cc757e67466ad4ce1 100644
7906
+ index 8a55c1bd666c4f7a032863f1527a2315830643c5..f7891682bd1903e45f96bd081f5af5a20a098edd 100644
7943
7907
--- a/uriloader/exthandler/nsIExternalHelperAppService.idl
7944
7908
+++ b/uriloader/exthandler/nsIExternalHelperAppService.idl
7945
- @@ -6,6 +6,7 @@
7909
+ @@ -6,6 +6,8 @@
7946
7910
7947
7911
#include "nsICancelable.idl"
7948
7912
7913
+ + webidl BrowsingContext;
7949
7914
+ interface nsIHelperAppLauncher;
7950
7915
interface nsIURI;
7951
7916
interface nsIRequest;
7952
7917
interface nsIStreamListener;
7953
- @@ -20,6 +21 ,17 @@ webidl BrowsingContext;
7918
+ @@ -20,6 +22 ,17 @@ webidl BrowsingContext;
7954
7919
class nsExternalAppHandler;
7955
7920
%}
7956
7921
@@ -7960,15 +7925,15 @@ index 8a55c1bd666c4f7a032863f1527a2315830643c5..c8bfff858079216798e0c71cc757e674
7960
7925
+ [scriptable, uuid(9a20e9b0-75d0-11ea-bc55-0242ac130003)]
7961
7926
+ interface nsIDownloadInterceptor : nsISupports
7962
7927
+ {
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);
7964
7929
+
7965
7930
+ void onDownloadComplete(in nsIHelperAppLauncher aHandler, in ACString aErrorName);
7966
7931
+ };
7967
7932
+
7968
7933
/**
7969
7934
* The external helper app service is used for finding and launching
7970
7935
* 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
7972
7937
in nsIInterfaceRequestor aContentContext,
7973
7938
in boolean aForceSave,
7974
7939
[optional] in nsIInterfaceRequestor aWindowContext);
@@ -7977,7 +7942,7 @@ index 8a55c1bd666c4f7a032863f1527a2315830643c5..c8bfff858079216798e0c71cc757e674
7977
7942
/**
7978
7943
* Binds an external helper application to a stream listener. The caller
7979
7944
* 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
7981
7946
boolean applyDecodingForExtension(in AUTF8String aExtension,
7982
7947
in ACString aEncodingType);
7983
7948
0 commit comments