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