Commit bdb7a794 authored by ap@apple.com's avatar ap@apple.com

window.crypto doesn't preserve custom properties

https://bugs.webkit.org/show_bug.cgi?id=122770

Reviewed by Mark Hahnenberg.

Source/WebCore: 

Test: security/crypto-gc.html

Generate isReachableFromOpaqueRoots that makes Crypto live as long as the document
lives (because that's when it's observable through window object).

* page/Crypto.cpp:
(WebCore::Crypto::Crypto):
(WebCore::Crypto::~Crypto):
(WebCore::Crypto::document):
* page/Crypto.h:
(WebCore::Crypto::create):
Made Crypto a ContextDestructionObserver, so that it can report its document to bindings.
Removed ScriptWrappable, because it seems to have served no purpose in this class.

* page/Crypto.idl: Added GenerateIsReachable. Removed ImplementationLacksVTable,
because the class now has a vtable, and can be checked for bindings integrity.

* page/DOMWindow.cpp: (WebCore::DOMWindow::crypto): Pass a document when creating
crypto.

LayoutTests: 

* security/crypto-gc-expected.txt: Added.
* security/crypto-gc.html: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@157417 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7edf26e5
2013-10-14 Alexey Proskuryakov <ap@apple.com>
window.crypto doesn't preserve custom properties
https://bugs.webkit.org/show_bug.cgi?id=122770
Reviewed by Mark Hahnenberg.
* security/crypto-gc-expected.txt: Added.
* security/crypto-gc.html: Added.
2013-10-14 Hans Muller <hmuller@adobe.com>
[CSS Shapes] Image valued shape-outside shapes should update the layout after the image has been loaded
......
Test that window.crypto wrapper preserves custom properties.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS window.crypto.foo is "bar"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../resources/js-test-pre.js"></script>
</head>
<body>
<script>
description("Test that window.crypto wrapper preserves custom properties.");
jsTestIsAsync = true;
function startTest()
{
window.crypto.foo = "bar";
gc();
setTimeout(continueTest, 10);
}
function continueTest()
{
gc();
setTimeout(finishTest, 10);
}
function finishTest()
{
gc();
shouldBe('window.crypto.foo', '"bar"');
finishJSTest();
}
window.onload = startTest;
</script>
<script src="../resources/js-test-post.js"></script>
</body>
</html>
2013-10-14 Alexey Proskuryakov <ap@apple.com>
window.crypto doesn't preserve custom properties
https://bugs.webkit.org/show_bug.cgi?id=122770
Reviewed by Mark Hahnenberg.
Test: security/crypto-gc.html
Generate isReachableFromOpaqueRoots that makes Crypto live as long as the document
lives (because that's when it's observable through window object).
* page/Crypto.cpp:
(WebCore::Crypto::Crypto):
(WebCore::Crypto::~Crypto):
(WebCore::Crypto::document):
* page/Crypto.h:
(WebCore::Crypto::create):
Made Crypto a ContextDestructionObserver, so that it can report its document to bindings.
Removed ScriptWrappable, because it seems to have served no purpose in this class.
* page/Crypto.idl: Added GenerateIsReachable. Removed ImplementationLacksVTable,
because the class now has a vtable, and can be checked for bindings integrity.
* page/DOMWindow.cpp: (WebCore::DOMWindow::crypto): Pass a document when creating
crypto.
2013-10-14 Andreas Kling <akling@apple.com>
CTTE: NamedNodeMap always has a corresponding Element.
......
......@@ -30,8 +30,8 @@
#include "config.h"
#include "Crypto.h"
#include "Document.h"
#include "ExceptionCode.h"
#include "ScriptWrappableInlines.h"
#include <runtime/ArrayBufferView.h>
#include <wtf/CryptographicallyRandomNumber.h>
......@@ -46,10 +46,20 @@ bool isIntegerArray(ArrayBufferView* array)
}
Crypto::Crypto()
Crypto::Crypto(Document& document)
: ContextDestructionObserver(&document)
{
}
Crypto::~Crypto()
{
}
Document* Crypto::document() const
{
return toDocument(scriptExecutionContext());
}
void Crypto::getRandomValues(ArrayBufferView* array, ExceptionCode& ec)
{
if (!array || !isIntegerArray(array)) {
......
......@@ -29,7 +29,7 @@
#ifndef Crypto_h
#define Crypto_h
#include "ScriptWrappable.h"
#include "ContextDestructionObserver.h"
#include <wtf/Forward.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
......@@ -42,14 +42,19 @@ namespace WebCore {
typedef int ExceptionCode;
class Crypto : public ScriptWrappable, public RefCounted<Crypto> {
class Document;
class Crypto : public ContextDestructionObserver, public RefCounted<Crypto> {
public:
static PassRefPtr<Crypto> create() { return adoptRef(new Crypto()); }
static PassRefPtr<Crypto> create(Document& document) { return adoptRef(new Crypto(document)); }
virtual ~Crypto();
Document* document() const;
void getRandomValues(JSC::ArrayBufferView*, ExceptionCode&);
private:
Crypto();
Crypto(Document&);
};
}
......
......@@ -28,7 +28,7 @@
[
NoInterfaceObject,
ImplementationLacksVTable,
GenerateIsReachable=ImplDocument,
OperationsNotDeletable
] interface Crypto {
[Custom, RaisesException] ArrayBufferView getRandomValues(ArrayBufferView array);
......
......@@ -591,10 +591,11 @@ History* DOMWindow::history() const
Crypto* DOMWindow::crypto() const
{
// FIXME: Why is crypto not available when the window is not currently displayed in a frame?
if (!isCurrentlyDisplayedInFrame())
return 0;
if (!m_crypto)
m_crypto = Crypto::create();
m_crypto = Crypto::create(*document());
return m_crypto.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