Source code

Revision control

Other Tools

1
/* vim: set ts=2 sw=2 sts=2 et tw=80: */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
* License, v. 2.0. If a copy of the MPL was not distributed with this
4
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
"use strict";
6
7
var EXPORTED_SYMBOLS = ["DOMFullscreenChild"];
8
9
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
10
11
class DOMFullscreenChild extends JSWindowActorChild {
12
receiveMessage(aMessage) {
13
let window = this.contentWindow;
14
let windowUtils = window && window.windowUtils;
15
16
if (!windowUtils) {
17
return;
18
}
19
20
switch (aMessage.name) {
21
case "DOMFullscreen:Entered": {
22
let remoteFrameBC = aMessage.data.remoteFrameBC;
23
if (remoteFrameBC) {
24
let remoteFrame = remoteFrameBC.embedderElement;
25
this._isNotTheRequestSource = true;
26
windowUtils.remoteFrameFullscreenChanged(remoteFrame);
27
} else {
28
this._lastTransactionId = windowUtils.lastTransactionId;
29
if (
30
!windowUtils.handleFullscreenRequests() &&
31
!this.document.fullscreenElement
32
) {
33
// If we don't actually have any pending fullscreen request
34
// to handle, neither we have been in fullscreen, tell the
35
// parent to just exit.
36
this.sendAsyncMessage("DOMFullscreen:Exit", {});
37
}
38
}
39
break;
40
}
41
case "DOMFullscreen:CleanUp": {
42
let remoteFrameBC = aMessage.data.remoteFrameBC;
43
if (remoteFrameBC) {
44
this._isNotTheRequestSource = true;
45
}
46
47
// If we've exited fullscreen at this point, no need to record
48
// transaction id or call exit fullscreen. This is especially
49
// important for pre-e10s, since in that case, it is possible
50
// that no more paint would be triggered after this point.
51
if (this.document.fullscreenElement) {
52
this._lastTransactionId = windowUtils.lastTransactionId;
53
windowUtils.exitFullscreen();
54
}
55
break;
56
}
57
case "DOMFullscreen:Painted": {
58
Services.obs.notifyObservers(this.contentWindow, "fullscreen-painted");
59
break;
60
}
61
}
62
}
63
64
handleEvent(aEvent) {
65
switch (aEvent.type) {
66
case "MozDOMFullscreen:Request": {
67
this.sendAsyncMessage("DOMFullscreen:Request", {});
68
break;
69
}
70
case "MozDOMFullscreen:NewOrigin": {
71
this.sendAsyncMessage("DOMFullscreen:NewOrigin", {
72
originNoSuffix: aEvent.target.nodePrincipal.originNoSuffix,
73
});
74
break;
75
}
76
case "MozDOMFullscreen:Exit": {
77
this.sendAsyncMessage("DOMFullscreen:Exit", {});
78
break;
79
}
80
case "MozDOMFullscreen:Entered":
81
case "MozDOMFullscreen:Exited": {
82
if (this._isNotTheRequestSource) {
83
// Fullscreen change event for a frame in the
84
// middle (content frame embedding the oop frame where the
85
// request comes from)
86
87
delete this._isNotTheRequestSource;
88
this.sendAsyncMessage(aEvent.type.replace("Moz", ""), {});
89
} else {
90
let rootWindow = this.contentWindow.windowRoot;
91
rootWindow.addEventListener("MozAfterPaint", this);
92
if (!this.document || !this.document.fullscreenElement) {
93
// If we receive any fullscreen change event, and find we are
94
// actually not in fullscreen, also ask the parent to exit to
95
// ensure that the parent always exits fullscreen when we do.
96
this.sendAsyncMessage("DOMFullscreen:Exit", {});
97
}
98
}
99
break;
100
}
101
case "MozAfterPaint": {
102
// Only send Painted signal after we actually finish painting
103
// the transition for the fullscreen change.
104
// Note that this._lastTransactionId is not set when in pre-e10s
105
// mode, so we need to check that explicitly.
106
if (
107
!this._lastTransactionId ||
108
aEvent.transactionId > this._lastTransactionId
109
) {
110
let rootWindow = this.contentWindow.windowRoot;
111
rootWindow.removeEventListener("MozAfterPaint", this);
112
this.sendAsyncMessage("DOMFullscreen:Painted", {});
113
}
114
break;
115
}
116
}
117
}
118
}