Bug 1456391 - Part 4: Use new mapFrameTree version for GeckoView. r=snorp

The copy-pasted description of mapFrameTree in GeckoView already claims to only
run the callback for *non*-dynamic child frames. With this patch we make
GeckoView actually do that and unify the behaviour with Desktop.

MozReview-Commit-ID: 6967vUcgB2r

--HG--
extra : rebase_source : 024dcda6d39e01ba8c9c2948a767200200383b37
This commit is contained in:
Jan Henning 2018-04-25 22:09:13 +02:00
parent 3dfb944b8d
commit 110831186a

View file

@ -11,6 +11,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
SessionHistory: "resource://gre/modules/sessionstore/SessionHistory.jsm",
FormData: "resource://gre/modules/FormData.jsm",
ScrollPosition: "resource://gre/modules/ScrollPosition.jsm",
Utils: "resource://gre/modules/sessionstore/Utils.jsm",
});
class GeckoViewContent extends GeckoViewContentModule {
@ -63,40 +64,9 @@ class GeckoViewContent extends GeckoViewContentModule {
this);
}
/**
* A function that will recursively call |cb| to collected data for all
* non-dynamic frames in the current frame/docShell tree.
*/
mapFrameTree(frame, cb) {
// Collect data for the current frame.
let callbacks = Array.isArray(cb) ? cb : [cb];
let objs = callbacks.map((callback) => callback(frame) || {});
let children = callbacks.map(() => []);
// Recurse into child frames.
for (let i = 0; i < frame.frames.length; i++) {
let subframe = frame.frames[i];
let results = this.mapFrameTree(subframe, callbacks);
results.forEach((result, j) => {
if (result && Object.keys(result).length) {
children[j][i] = result;
}
});
}
objs.forEach((obj, i) => {
if (children[i].length) {
obj.children = children[i];
}
});
let res = objs.map((obj) => Object.keys(obj).length ? obj : null);
return Array.isArray(cb) ? res : res[0];
}
collectSessionState() {
let history = SessionHistory.collect(docShell);
let [formdata, scrolldata] = this.mapFrameTree(content, [FormData.collect, ScrollPosition.collect]);
let [formdata, scrolldata] = Utils.mapFrameTree(content, FormData.collect, ScrollPosition.collect);
// Save the current document resolution.
let zoom = { value: 1 };