Skip to content

Commit 951cdf9

Browse files
committed
Bug 1423295 - Make pageloader use plain .js files - r=rwood
MozReview-Commit-ID: JDd5WUHMhL3 --HG-- extra : rebase_source : 76bfbac4e3e43a87f04f3bb9ff694adf27fe3e2c
1 parent f695922 commit 951cdf9

File tree

5 files changed

+85
-58
lines changed

5 files changed

+85
-58
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
function _dummy() {
5+
sendAsyncMessage("PageLoader:LoadEvent", {});
6+
}
7+
8+
addEventListener("load", contentLoadHandlerCallback(_dummy), true); // eslint-disable-line no-undef
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
var gRetryCounter = 0;
5+
6+
7+
function _contentFNBPaintHandler() {
8+
var x = content.window.performance.timing.timeToNonBlankPaint;
9+
if (typeof x == "undefined") {
10+
sendAsyncMessage("PageLoader:FNBPaintError", {});
11+
}
12+
if (x > 0) {
13+
sendAsyncMessage("PageLoader:LoadEvent", {"fnbpaint": x});
14+
} else {
15+
gRetryCounter += 1;
16+
if (gRetryCounter <= 10) {
17+
dump("fnbpaint is not yet available (0), retry number " + gRetryCounter + "...\n");
18+
content.setTimeout(_contentFNBPaintHandler, 100);
19+
} else {
20+
dump("unable to get a value for fnbpaint after " + gRetryCounter + " retries\n");
21+
sendAsyncMessage("PageLoader:FNBPaintError", {});
22+
}
23+
}
24+
}
25+
26+
addEventListener("load", contentLoadHandlerCallback(_contentFNBPaintHandler), true); // eslint-disable-line no-undef
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
function _contentPaintHandler() {
5+
var utils = content.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils);
6+
if (utils.isMozAfterPaintPending) {
7+
addEventListener("MozAfterPaint", function afterpaint(e) {
8+
removeEventListener("MozAfterPaint", afterpaint, true);
9+
sendAsyncMessage("PageLoader:LoadEvent", {});
10+
}, true);
11+
} else {
12+
sendAsyncMessage("PageLoader:LoadEvent", {});
13+
}
14+
}
15+
16+
17+
addEventListener("load", contentLoadHandlerCallback(_contentPaintHandler), true); // eslint-disable-line no-undef

testing/talos/talos/pageloader/chrome/pageloader.js

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -230,69 +230,18 @@ function plInit() {
230230
browserWindow.resizeTo(winWidth, winHeight);
231231
browserWindow.moveTo(0, 0);
232232
browserWindow.focus();
233-
234233
content = browserWindow.getBrowser();
234+
content.selectedBrowser.messageManager.loadFrameScript("chrome://pageloader/content/utils.js", false, true);
235235

236-
// Load the frame script for e10s / IPC message support
237-
let contentScript = "data:,function _contentLoadHandler(e) { " +
238-
" if (e.originalTarget.defaultView == content) { " +
239-
" content.wrappedJSObject.tpRecordTime = function(t, s, n) { sendAsyncMessage('PageLoader:RecordTime', { time: t, startTime: s, testName: n }); }; ";
240-
// setup idle-callback
241-
contentScript += "" +
242-
"var idleCallbackHandle; " +
243-
"function _idleCallbackHandler() { " +
244-
" content.window.cancelIdleCallback(idleCallbackHandle); " +
245-
" sendAsyncMessage('PageLoader:IdleCallbackReceived', {}); " +
246-
"}; " +
247-
"function _setIdleCallback() { " +
248-
" idleCallbackHandle = content.window.requestIdleCallback(_idleCallbackHandler); " +
249-
" sendAsyncMessage('PageLoader:IdleCallbackSet', {}); " +
250-
"}; ";
236+
// pick the right load handler
251237
if (useFNBPaint) {
252-
contentScript += "" +
253-
"var gRetryCounter = 0; " +
254-
"function _contentFNBPaintHandler() { " +
255-
" x = content.window.performance.timing.timeToNonBlankPaint; " +
256-
" if (typeof x == 'undefined') { " +
257-
" sendAsyncMessage('PageLoader:FNBPaintError', {}); " +
258-
" } " +
259-
" if (x > 0) { " +
260-
" sendAsyncMessage('PageLoader:LoadEvent', { 'fnbpaint': x }); " +
261-
" } else { " +
262-
" gRetryCounter += 1; " +
263-
" if (gRetryCounter <= 10) { " +
264-
" dump('fnbpaint is not yet available (0), retry number ' + gRetryCounter + '...\\n'); " +
265-
" content.setTimeout(_contentFNBPaintHandler, 100); " +
266-
" } else { " +
267-
" dump('unable to get a value for fnbpaint after ' + gRetryCounter + ' retries\\n'); " +
268-
" sendAsyncMessage('PageLoader:FNBPaintError', {}); " +
269-
" } " +
270-
" } " +
271-
"}; " +
272-
"content.setTimeout(_contentFNBPaintHandler, 0); ";
238+
content.selectedBrowser.messageManager.loadFrameScript("chrome://pageloader/content/lh_fnbpaint.js", false, true);
273239
} else if (useMozAfterPaint) {
274-
contentScript += "" +
275-
"function _contentPaintHandler() { " +
276-
" var utils = content.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils); " +
277-
" if (utils.isMozAfterPaintPending) { " +
278-
" addEventListener('MozAfterPaint', function(e) { " +
279-
" removeEventListener('MozAfterPaint', arguments.callee, true); " +
280-
" sendAsyncMessage('PageLoader:LoadEvent', {}); " +
281-
" }, true); " +
282-
" } else { " +
283-
" sendAsyncMessage('PageLoader:LoadEvent', {}); " +
284-
" } " +
285-
"}; " +
286-
"content.setTimeout(_contentPaintHandler, 0); ";
240+
content.selectedBrowser.messageManager.loadFrameScript("chrome://pageloader/content/lh_moz.js", false, true);
287241
} else {
288-
contentScript += " sendAsyncMessage('PageLoader:LoadEvent', {}); ";
242+
content.selectedBrowser.messageManager.loadFrameScript("chrome://pageloader/content/lh_dummy.js", false, true);
243+
289244
}
290-
contentScript += "" +
291-
" content.setTimeout(_setIdleCallback, 0); " +
292-
" }" +
293-
"} " +
294-
"addEventListener('load', _contentLoadHandler, true); ";
295-
content.selectedBrowser.messageManager.loadFrameScript(contentScript, false, true);
296245
content.selectedBrowser.messageManager.loadFrameScript("chrome://pageloader/content/talos-content.js", false);
297246
content.selectedBrowser.messageManager.loadFrameScript("chrome://pageloader/content/tscroll.js", false, true);
298247
content.selectedBrowser.messageManager.loadFrameScript("chrome://pageloader/content/Profiler.js", false, true);
@@ -675,7 +624,6 @@ function _loadHandler(fnbpaint = 0) {
675624
}
676625

677626
var duration = (end_time - start_time);
678-
679627
TalosParentProfiler.pause("Bubbling load handler fired.");
680628

681629
// does this page want to do its own timing?
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
var idleCallbackHandle;
5+
6+
7+
function _idleCallbackHandler() {
8+
content.window.cancelIdleCallback(idleCallbackHandle);
9+
sendAsyncMessage("PageLoader:IdleCallbackReceived", {});
10+
}
11+
12+
function setIdleCallback() {
13+
idleCallbackHandle = content.window.requestIdleCallback(_idleCallbackHandler);
14+
sendAsyncMessage("PageLoader:IdleCallbackSet", {});
15+
}
16+
17+
function contentLoadHandlerCallback(cb) {
18+
function _handler(e) {
19+
if (e.originalTarget.defaultView == content) {
20+
content.wrappedJSObject.tpRecordTime = function(t, s, n) {
21+
sendAsyncMessage("PageLoader:RecordTime", {time: t, startTime: s, testName: n});
22+
};
23+
content.setTimeout(cb, 0);
24+
content.setTimeout(setIdleCallback, 0);
25+
}
26+
}
27+
return _handler;
28+
}

0 commit comments

Comments
 (0)