Commit b9a13914 authored by Yi Su's avatar Yi Su Committed by Commit Bot

Fix logic defect of while-loop in find_in_page.js

This CL fixes a logic defect of a while-loop in the "isElementVisible_"
function of find_in_page.js. This defect may cause a Js exception of
trying to get "ownerDocument" property on "null".

Bug: 912717
Change-Id: I32b39315983004b28fd6a2000b9ff7317225f8bf
Reviewed-on: https://chromium-review.googlesource.com/c/1370173Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615477}
parent 5e71410f
...@@ -879,8 +879,6 @@ function isElementVisible_(elem) { ...@@ -879,8 +879,6 @@ function isElementVisible_(elem) {
let originalElement = elem; let originalElement = elem;
let nextOffsetParent = originalElement.offsetParent; let nextOffsetParent = originalElement.offsetParent;
let computedStyle =
elem.ownerDocument.defaultView.getComputedStyle(elem, null);
// We are currently handling all scrolling through the app, which means we can // We are currently handling all scrolling through the app, which means we can
// only scroll the window, not any scrollable containers in the DOM itself. So // only scroll the window, not any scrollable containers in the DOM itself. So
...@@ -891,6 +889,9 @@ function isElementVisible_(elem) { ...@@ -891,6 +889,9 @@ function isElementVisible_(elem) {
let bodyWidth = getBodyWidth_(); let bodyWidth = getBodyWidth_();
while (elem && elem.nodeName.toUpperCase() != 'BODY') { while (elem && elem.nodeName.toUpperCase() != 'BODY') {
let computedStyle =
elem.ownerDocument.defaultView.getComputedStyle(elem, null);
if (elem.style.display === 'none' || elem.style.visibility === 'hidden' || if (elem.style.display === 'none' || elem.style.visibility === 'hidden' ||
elem.style.opacity === 0 || computedStyle.display === 'none' || elem.style.opacity === 0 || computedStyle.display === 'none' ||
computedStyle.visibility === 'hidden' || computedStyle.opacity === 0) { computedStyle.visibility === 'hidden' || computedStyle.opacity === 0) {
...@@ -925,7 +926,6 @@ function isElementVisible_(elem) { ...@@ -925,7 +926,6 @@ function isElementVisible_(elem) {
} }
elem = elem.parentNode; elem = elem.parentNode;
computedStyle = elem.ownerDocument.defaultView.getComputedStyle(elem, null);
} }
return true; return true;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment