-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathRemoteWebProgress.jsm
161 lines (141 loc) · 3.98 KB
/
RemoteWebProgress.jsm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
var EXPORTED_SYMBOLS = ["RemoteWebProgressManager"];
const RemoteWebProgress = Components.Constructor(
"@mozilla.org/dom/remote-web-progress;1",
"nsIRemoteWebProgress",
"init"
);
class RemoteWebProgressManager {
constructor(aBrowser) {
this._topLevelWebProgress = new RemoteWebProgress(
this.QueryInterface(Ci.nsIWebProgress),
/* aIsTopLevel = */ true
);
this._progressListeners = [];
this.swapBrowser(aBrowser);
}
swapBrowser(aBrowser) {
this._browser = aBrowser;
}
swapListeners(aOtherRemoteWebProgressManager) {
let temp = aOtherRemoteWebProgressManager.progressListeners;
aOtherRemoteWebProgressManager._progressListeners = this._progressListeners;
this._progressListeners = temp;
}
get progressListeners() {
return this._progressListeners;
}
get topLevelWebProgress() {
return this._topLevelWebProgress;
}
addProgressListener(aListener, aNotifyMask) {
let listener = aListener.QueryInterface(Ci.nsIWebProgressListener);
this._progressListeners.push({
listener,
mask: aNotifyMask || Ci.nsIWebProgress.NOTIFY_ALL,
});
}
removeProgressListener(aListener) {
this._progressListeners = this._progressListeners.filter(
l => l.listener != aListener
);
}
setCurrentURI(aURI) {
// This function is simpler than nsDocShell::SetCurrentURI since
// it doesn't have to deal with child docshells.
let remoteWebNav = this._browser._remoteWebNavigationImpl;
remoteWebNav._currentURI = aURI;
let webProgress = this.topLevelWebProgress;
for (let { listener, mask } of this._progressListeners) {
if (mask & Ci.nsIWebProgress.NOTIFY_LOCATION) {
listener.onLocationChange(webProgress, null, aURI);
}
}
}
_callProgressListeners(type, methodName, ...args) {
for (let { listener, mask } of this._progressListeners) {
if (mask & type && listener[methodName]) {
try {
listener[methodName].apply(listener, args);
} catch (ex) {
Cu.reportError(
"RemoteWebProgress failed to call " + methodName + ": " + ex + "\n"
);
}
}
}
}
onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
this._callProgressListeners(
Ci.nsIWebProgress.NOTIFY_STATE_ALL,
"onStateChange",
aWebProgress,
aRequest,
aStateFlags,
aStatus
);
}
onProgressChange(
aWebProgress,
aRequest,
aCurSelfProgress,
aMaxSelfProgress,
aCurTotalProgress,
aMaxTotalProgress
) {
this._callProgressListeners(
Ci.nsIWebProgress.NOTIFY_PROGRESS,
"onProgressChange",
aWebProgress,
aRequest,
aCurSelfProgress,
aMaxSelfProgress,
aCurTotalProgress,
aMaxTotalProgress
);
}
onLocationChange(aWebProgress, aRequest, aLocation, aFlags) {
this._callProgressListeners(
Ci.nsIWebProgress.NOTIFY_LOCATION,
"onLocationChange",
aWebProgress,
aRequest,
aLocation,
aFlags
);
}
onStatusChange(aWebProgress, aRequest, aStatus, aMessage) {
this._callProgressListeners(
Ci.nsIWebProgress.NOTIFY_STATUS,
"onStatusChange",
aWebProgress,
aRequest,
aStatus,
aMessage
);
}
onSecurityChange(aWebProgress, aRequest, aState) {
this._callProgressListeners(
Ci.nsIWebProgress.NOTIFY_SECURITY,
"onSecurityChange",
aWebProgress,
aRequest,
aState
);
}
onContentBlockingEvent(aWebProgress, aRequest, aEvent) {
this._callProgressListeners(
Ci.nsIWebProgress.NOTIFY_CONTENT_BLOCKING,
"onContentBlockingEvent",
aWebProgress,
aRequest,
aEvent
);
}
}
RemoteWebProgressManager.prototype.QueryInterface = ChromeUtils.generateQI([
"nsIWebProgress",
"nsIWebProgressListener",
]);