browser(firefox): introduce browser level screencastFinished event (#3625)
This commit is contained in:
parent
a0bd8def74
commit
17077fd901
|
|
@ -1,2 +1,2 @@
|
|||
1166
|
||||
Changed: yurys@chromium.org Thu Aug 20 13:55:50 PDT 2020
|
||||
1167
|
||||
Changed: yurys@chromium.org Tue Aug 25 14:46:17 PDT 2020
|
||||
|
|
|
|||
|
|
@ -134,8 +134,7 @@ class TargetRegistry {
|
|||
if (!target)
|
||||
return;
|
||||
target.emit('crashed');
|
||||
if (target)
|
||||
target.dispose().catch(e => dump(`Failed to destroy target: ${e}`));
|
||||
target.dispose();
|
||||
}
|
||||
}, 'oop-frameloader-crashed');
|
||||
|
||||
|
|
@ -204,7 +203,7 @@ class TargetRegistry {
|
|||
const linkedBrowser = tab.linkedBrowser;
|
||||
const target = this._browserToTarget.get(linkedBrowser);
|
||||
if (target)
|
||||
target.dispose().catch(e => dump(`Failed to destroy target: ${e}`));
|
||||
target.dispose();
|
||||
};
|
||||
|
||||
Services.wm.addListener({
|
||||
|
|
@ -460,17 +459,12 @@ class PageTarget {
|
|||
return await this._channel.connect('').send('hasFailedToOverrideTimezone').catch(e => true);
|
||||
}
|
||||
|
||||
async dispose() {
|
||||
dispose() {
|
||||
this._disposed = true;
|
||||
this._browserContext.pages.delete(this);
|
||||
this._registry._browserToTarget.delete(this._linkedBrowser);
|
||||
this._registry._browserBrowsingContextToTarget.delete(this._linkedBrowser.browsingContext);
|
||||
helper.removeListeners(this._eventListeners);
|
||||
|
||||
const event = { pendingActivity: [], target: this };
|
||||
this._registry.emit(TargetRegistry.Events.TargetWillBeDestroyed, event);
|
||||
await Promise.all(event.pendingActivity);
|
||||
|
||||
this._browserContext.pages.delete(this);
|
||||
this._registry.emit(TargetRegistry.Events.TargetDestroyed, this);
|
||||
}
|
||||
}
|
||||
|
|
@ -740,7 +734,6 @@ function setViewportSizeForBrowser(viewportSize, browser, window) {
|
|||
|
||||
TargetRegistry.Events = {
|
||||
TargetCreated: Symbol('TargetRegistry.Events.TargetCreated'),
|
||||
TargetWillBeDestroyed: Symbol('TargetRegistry.Events.TargetWillBeDestroyed'),
|
||||
TargetDestroyed: Symbol('TargetRegistry.Events.TargetDestroyed'),
|
||||
DownloadCreated: Symbol('TargetRegistry.Events.DownloadCreated'),
|
||||
DownloadFinished: Symbol('TargetRegistry.Events.DownloadFinished'),
|
||||
|
|
|
|||
|
|
@ -44,10 +44,16 @@ class BrowserHandler {
|
|||
|
||||
this._eventListeners = [
|
||||
helper.on(this._targetRegistry, TargetRegistry.Events.TargetCreated, this._onTargetCreated.bind(this)),
|
||||
helper.on(this._targetRegistry, TargetRegistry.Events.TargetWillBeDestroyed, this._onTargetWillBeDestroyed.bind(this)),
|
||||
helper.on(this._targetRegistry, TargetRegistry.Events.TargetDestroyed, this._onTargetDestroyed.bind(this)),
|
||||
helper.on(this._targetRegistry, TargetRegistry.Events.DownloadCreated, this._onDownloadCreated.bind(this)),
|
||||
helper.on(this._targetRegistry, TargetRegistry.Events.DownloadFinished, this._onDownloadFinished.bind(this)),
|
||||
];
|
||||
|
||||
const onScreencastStopped = (subject, topic, data) => {
|
||||
this._session.emitEvent('Browser.screencastFinished', {screencastId: '' + data});
|
||||
};
|
||||
Services.obs.addObserver(onScreencastStopped, 'juggler-screencast-stopped');
|
||||
this._eventListeners.push(() => Services.obs.removeObserver(onScreencastStopped, 'juggler-screencast-stopped'));
|
||||
}
|
||||
|
||||
async createBrowserContext({removeOnDetach}) {
|
||||
|
|
@ -65,11 +71,11 @@ class BrowserHandler {
|
|||
this._createdBrowserContextIds.delete(browserContextId);
|
||||
}
|
||||
|
||||
async dispose() {
|
||||
dispose() {
|
||||
helper.removeListeners(this._eventListeners);
|
||||
for (const [target, session] of this._attachedSessions) {
|
||||
target.disconnectSession(session);
|
||||
await this._dispatcher.destroySession(session);
|
||||
this._dispatcher.destroySession(session);
|
||||
}
|
||||
this._attachedSessions.clear();
|
||||
for (const browserContextId of this._createdBrowserContextIds) {
|
||||
|
|
@ -101,16 +107,12 @@ class BrowserHandler {
|
|||
sessions.push(session);
|
||||
}
|
||||
|
||||
_onTargetWillBeDestroyed({target, pendingActivity}) {
|
||||
pendingActivity.push(this._detachFromTarget(target));
|
||||
}
|
||||
|
||||
async _detachFromTarget(target) {
|
||||
_onTargetDestroyed(target) {
|
||||
const session = this._attachedSessions.get(target);
|
||||
if (!session)
|
||||
return;
|
||||
this._attachedSessions.delete(target);
|
||||
await this._dispatcher.destroySession(session);
|
||||
this._dispatcher.destroySession(session);
|
||||
this._session.emitEvent('Browser.detachedFromTarget', {
|
||||
sessionId: session.sessionId(),
|
||||
targetId: target.id(),
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ class Dispatcher {
|
|||
return session;
|
||||
}
|
||||
|
||||
async destroySession(session) {
|
||||
destroySession(session) {
|
||||
this._sessions.delete(session.sessionId());
|
||||
await session._dispose();
|
||||
session._dispose();
|
||||
}
|
||||
|
||||
_dispose() {
|
||||
|
|
@ -108,15 +108,13 @@ class ProtocolSession {
|
|||
this._handlers.set(domainName, handler);
|
||||
}
|
||||
|
||||
async _dispose() {
|
||||
const promises = [];
|
||||
_dispose() {
|
||||
for (const [domainName, handler] of this._handlers) {
|
||||
if (typeof handler.dispose !== 'function')
|
||||
throw new Error(`Handler for "${domainName}" domain does not define |dispose| method!`);
|
||||
promises.push(handler.dispose());
|
||||
handler.dispose();
|
||||
}
|
||||
this._handlers.clear();
|
||||
await Promise.all(promises);
|
||||
this._dispatcher = null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -311,7 +311,7 @@ class PageHandler {
|
|||
const rect = this._pageTarget.linkedBrowser().getBoundingClientRect();
|
||||
const devicePixelRatio = this._pageTarget._window.devicePixelRatio;
|
||||
this._videoSessionId = screencast.startVideoRecording(docShell, file, width, height, scale || 0, devicePixelRatio * rect.top);
|
||||
this._session.emitEvent('Page.screencastStarted', {uid: '' + this._videoSessionId, file});
|
||||
this._session.emitEvent('Page.screencastStarted', {screencastId: '' + this._videoSessionId, file});
|
||||
}
|
||||
|
||||
async stopVideoRecording() {
|
||||
|
|
@ -320,7 +320,6 @@ class PageHandler {
|
|||
const videoSessionId = this._videoSessionId;
|
||||
this._videoSessionId = -1;
|
||||
const screencast = Cc['@mozilla.org/juggler/screencast;1'].getService(Ci.nsIScreencastService);
|
||||
const session = this._session;
|
||||
const result = new Promise(resolve =>
|
||||
Services.obs.addObserver(function onStopped(subject, topic, data) {
|
||||
if (videoSessionId != data)
|
||||
|
|
@ -328,8 +327,6 @@ class PageHandler {
|
|||
|
||||
Services.obs.removeObserver(onStopped, 'juggler-screencast-stopped');
|
||||
resolve();
|
||||
|
||||
session.emitEvent('Page.screencastStopped', {uid: '' + videoSessionId});
|
||||
}, 'juggler-screencast-stopped')
|
||||
);
|
||||
screencast.stopVideoRecording(videoSessionId);
|
||||
|
|
|
|||
|
|
@ -216,6 +216,9 @@ const Browser = {
|
|||
canceled: t.Optional(t.Boolean),
|
||||
error: t.Optional(t.String),
|
||||
},
|
||||
'screencastFinished': {
|
||||
screencastId: t.String,
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
|
@ -650,12 +653,9 @@ const Page = {
|
|||
message: t.String,
|
||||
},
|
||||
'screencastStarted': {
|
||||
uid: t.String,
|
||||
screencastId: t.String,
|
||||
file: t.String,
|
||||
},
|
||||
'screencastStopped': {
|
||||
uid: t.String,
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue