Commit c62d8db2 authored by yhirano@chromium.org's avatar yhirano@chromium.org

DOMWindow::navigator should return a navigator w/o frame when detached.

Currently DOMWindow::navigator returns a navigator associated with a frame
even when the window is detached from the frame and another window
is attached to it. That means calling frame()->document() may return
an incorrect document, for example.

This CL makes LocalDOMWindow::navigator return a navigator with
a null frame when the window is not associated to the frame.

BUG=522791

Review URL: https://codereview.chromium.org/1308723003

git-svn-id: svn://svn.chromium.org/blink/trunk@201055 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 63f6bb43
<!DOCTYPE html>
<html>
<head>
<title>navigator.serviceWorker should return null when frame is detached</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<iframe id="subframe" src="about:blank"></iframe>
<script>
promise_test(function(t) {
var iframe = document.querySelector("#subframe");
var f = iframe.contentWindow.Function;
function get_navigator() {
return f("return navigator")();
}
return new Promise(function(resolve) {
assert_equals(iframe.contentWindow.navigator, get_navigator());
iframe.src = "resources/a.html";
iframe.onload = resolve;
}).then(function() {
assert_equals(get_navigator().serviceWorker, null);
});
});
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>navigator.serviceWorker should return null when frame is removed</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<iframe id="subframe" src="about:blank"></iframe>
<script>
test(function(t) {
var iframe = document.querySelector("#subframe");
var f = iframe.contentWindow.Function;
function get_navigator() {
return f("return navigator")();
}
iframe.remove();
assert_equals(get_navigator().serviceWorker, null);
});
done();
</script>
</body>
</html>
......@@ -661,8 +661,17 @@ ApplicationCache* LocalDOMWindow::applicationCache() const
Navigator* LocalDOMWindow::navigator() const
{
if (!isCurrentlyDisplayedInFrame() && (!m_navigator || m_navigator->frame())) {
// We return a navigator with null frame instead of returning null
// pointer as other functions do, in order to allow users to access
// functions such as navigator.product.
m_navigator = Navigator::create(nullptr);
}
if (!m_navigator)
m_navigator = Navigator::create(frame());
// As described above, when not dispayed in the frame, the returning
// navigator should not be associated with the frame.
ASSERT(isCurrentlyDisplayedInFrame() || !m_navigator->frame());
return m_navigator.get();
}
......
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