Bug 1697836 - Avoid throwing when asking for a selection. r=emalysz

Selection may be null if the page got hidden in e.g., the afterprint
event listener or somewhere else.

Add a try catch for good measure, assuming there's no selection is
always safe.

I'll try to get an automated test-case for this working, though it might
be tricky.

Depends on D109714

Differential Revision: https://phabricator.services.mozilla.com/D109715
This commit is contained in:
Emilio Cobos Álvarez 2021-03-27 10:22:55 +00:00
Родитель 188f91724f
Коммит 06b663afd4
2 изменённых файлов: 6 добавлений и 5 удалений

Просмотреть файл

@ -22,9 +22,8 @@ class PrintingSelectionChild extends JSWindowActorChild {
let focusedWindow = Services.focus.focusedWindow;
if (focusedWindow) {
let selection = focusedWindow.getSelection();
return selection.type == "Range";
return selection && selection.type == "Range";
}
return false;
}
}

Просмотреть файл

@ -235,9 +235,11 @@ var PrintUtils = {
let sourceActor = aBrowsingContext.currentWindowGlobal.getActor(
"PrintingSelection"
);
hasSelection = await sourceActor.sendQuery(
"PrintingSelection:HasSelection"
);
try {
hasSelection = await sourceActor.sendQuery(
"PrintingSelection:HasSelection"
);
} catch (ex) {}
}
let sourceBrowser = aBrowsingContext.top.embedderElement;