2011-02-10 Adam Barth <abarth@webkit.org>
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Feb 2011 08:37:36 +0000 (08:37 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Feb 2011 08:37:36 +0000 (08:37 +0000)
        Reviewed by Eric Seidel.

        WebKit should have a cryptographic RNG
        https://bugs.webkit.org/show_bug.cgi?id=22049

        Test crypto.getRandomValues API.  It's pretty hard to write a
        deterministic API for a randomized API, but this test should catch some
        regressions.

        * security/crypto-random-values-expected.txt: Added.
        * security/crypto-random-values.html: Added.
2011-02-10  Adam Barth  <abarth@webkit.org>

        Reviewed by Eric Seidel.

        WebKit should have a cryptographic RNG
        https://bugs.webkit.org/show_bug.cgi?id=22049

        Teach JavaScriptCore how to export this function.

        * JavaScriptCore.exp:
        * JavaScriptCore.xcodeproj/project.pbxproj:
2011-02-10  Adam Barth  <abarth@webkit.org>

        Reviewed by Eric Seidel.

        WebKit should have a cryptographic RNG
        https://bugs.webkit.org/show_bug.cgi?id=22049

        Add crypto.getRandomValues.  Yes, all these diffs are required to
        expose a single function to the DOM.

        Test: security/crypto-random-values.html

        * Android.mk:
        * CMakeLists.txt:
        * DerivedSources.cpp:
        * DerivedSources.make:
        * ForwardingHeaders/wtf/CryptographicallyRandomNumber.h: Added.
        * GNUmakefile.am:
        * WebCore.gypi:
        * WebCore.pri:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * bindings/js/JSDOMWindowCustom.cpp:
        * bindings/v8/custom/V8DOMWindowCustom.cpp:
        * config.h:
        * page/Crypto.cpp: Added.
        (WebCore::Crypto::Crypto):
        (WebCore::Crypto::getRandomValues):
        * page/Crypto.h: Added.
        (WebCore::Crypto::create):
        * page/Crypto.idl: Added.
        * page/DOMWindow.cpp:
        (WebCore::DOMWindow::clear):
        (WebCore::DOMWindow::crypto):
        * page/DOMWindow.h:
        (WebCore::DOMWindow::optionalCrypto):
        * page/DOMWindow.idl:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@78321 268f45cc-cd09-0410-ab3c-d52691b4dbfc

27 files changed:
LayoutTests/ChangeLog
LayoutTests/security/crypto-random-values-expected.txt [new file with mode: 0644]
LayoutTests/security/crypto-random-values.html [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.exp
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/WebCore/Android.mk
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.cpp
Source/WebCore/DerivedSources.make
Source/WebCore/ForwardingHeaders/wtf/CryptographicallyRandomNumber.h [new file with mode: 0644]
Source/WebCore/GNUmakefile.am
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.pri
Source/WebCore/WebCore.pro
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSDOMWindowCustom.cpp
Source/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp
Source/WebCore/config.h
Source/WebCore/page/Crypto.cpp [new file with mode: 0644]
Source/WebCore/page/Crypto.h [new file with mode: 0644]
Source/WebCore/page/Crypto.idl [new file with mode: 0644]
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DOMWindow.h
Source/WebCore/page/DOMWindow.idl

index aa86c91..29bdf10 100644 (file)
@@ -1,3 +1,17 @@
+2011-02-10  Adam Barth  <abarth@webkit.org>
+
+        Reviewed by Eric Seidel.
+
+        WebKit should have a cryptographic RNG
+        https://bugs.webkit.org/show_bug.cgi?id=22049
+
+        Test crypto.getRandomValues API.  It's pretty hard to write a
+        deterministic API for a randomized API, but this test should catch some
+        regressions.
+
+        * security/crypto-random-values-expected.txt: Added.
+        * security/crypto-random-values.html: Added.
+
 2011-02-10  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Dan Bernstein.
diff --git a/LayoutTests/security/crypto-random-values-expected.txt b/LayoutTests/security/crypto-random-values-expected.txt
new file mode 100644 (file)
index 0000000..d9fce8f
--- /dev/null
@@ -0,0 +1,12 @@
+Tests crypto.randomValues.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS 'crypto' in window is true
+PASS 'getRandomValues' in window.crypto is true
+PASS matchingBytes < 100 is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/security/crypto-random-values.html b/LayoutTests/security/crypto-random-values.html
new file mode 100644 (file)
index 0000000..80005f2
--- /dev/null
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href="../fast/js/resources/js-test-style.css">
+<script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/utilities.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description("Tests crypto.randomValues.");
+
+if (!window.ArrayBuffer)
+    debug("This test requres ArrayBuffers to run!");
+
+shouldBe("'crypto' in window", "true");
+shouldBe("'getRandomValues' in window.crypto", "true");
+
+try {
+    // FIXME: This test is flaky.  If we ran this test every second since the
+    //        beginning of the universe, on average, it would have failed
+    //        2^{-748} times.
+
+    var reference = new Uint8Array(100);
+    var sample = new Uint8Array(100);
+
+    crypto.getRandomValues(reference);
+    crypto.getRandomValues(sample);
+
+    var matchingBytes = 0;
+
+    for (var i = 0; i < reference.length; i++) {
+        if (reference[i] == sample[i])
+            matchingBytes++;
+    }
+
+    shouldBe("matchingBytes < 100", "true");
+} catch(ex) {
+    debug(ex);
+}
+
+var successfullyParsed = true;
+</script>
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
+
+
index 94ec20b..927ce2c 100644 (file)
@@ -1,3 +1,15 @@
+2011-02-10  Adam Barth  <abarth@webkit.org>
+
+        Reviewed by Eric Seidel.
+
+        WebKit should have a cryptographic RNG
+        https://bugs.webkit.org/show_bug.cgi?id=22049
+
+        Teach JavaScriptCore how to export this function.
+
+        * JavaScriptCore.exp:
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+
 2011-02-10  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Sam Weinig.
index cd370c5..173a1ca 100644 (file)
@@ -433,6 +433,7 @@ __ZN3WTF23dayInMonthFromDayInYearEib
 __ZN3WTF23waitForThreadCompletionEjPPv
 __ZN3WTF27releaseFastMallocFreeMemoryEv
 __ZN3WTF28setMainThreadCallbacksPausedEb
+__ZN3WTF29cryptographicallyRandomValuesEPvm
 __ZN3WTF36lockAtomicallyInitializedStaticMutexEv
 __ZN3WTF37parseDateFromNullTerminatedCharactersEPKc
 __ZN3WTF38unlockAtomicallyInitializedStaticMutexEv
index d48139f..084a3c9 100644 (file)
                97941A5713029AAB004A3447 /* OSRandomSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97941A3F130299DB004A3447 /* OSRandomSource.cpp */; };
                97941A5A13029ACC004A3447 /* OSRandomSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 97941A40130299DB004A3447 /* OSRandomSource.h */; };
                97941A7E1302A098004A3447 /* CryptographicallyRandomNumber.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97941A7C1302A098004A3447 /* CryptographicallyRandomNumber.cpp */; };
-               97941A7F1302A098004A3447 /* CryptographicallyRandomNumber.h in Headers */ = {isa = PBXBuildFile; fileRef = 97941A7D1302A098004A3447 /* CryptographicallyRandomNumber.h */; };
+               97941A7F1302A098004A3447 /* CryptographicallyRandomNumber.h in Headers */ = {isa = PBXBuildFile; fileRef = 97941A7D1302A098004A3447 /* CryptographicallyRandomNumber.h */; settings = {ATTRIBUTES = (Private, ); }; };
                A1712B3B11C7B212007A5315 /* RegExpCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1712B3A11C7B212007A5315 /* RegExpCache.cpp */; };
                A1712B3F11C7B228007A5315 /* RegExpCache.h in Headers */ = {isa = PBXBuildFile; fileRef = A1712B3E11C7B228007A5315 /* RegExpCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
                A1712B4111C7B235007A5315 /* RegExpKey.h in Headers */ = {isa = PBXBuildFile; fileRef = A1712B4011C7B235007A5315 /* RegExpKey.h */; settings = {ATTRIBUTES = (Private, ); }; };
index 682a718..9cd3022 100644 (file)
@@ -409,6 +409,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
        page/Console.cpp \
        page/ContentSecurityPolicy.cpp \
        page/ContextMenuController.cpp \
+       page/Crypto.cpp \
        page/DOMSelection.cpp \
        page/DOMTimer.cpp \
        page/DOMWindow.cpp \
index 04ad20c..fd6ff44 100644 (file)
@@ -319,6 +319,7 @@ SET(WebCore_IDL_FILES
     page/BarInfo.idl
     page/Console.idl
     page/Coordinates.idl
+    page/Crypto.idl
     page/DOMSelection.idl
     page/DOMWindow.idl
     page/EventSource.idl
@@ -1110,6 +1111,7 @@ SET(WebCore_SOURCES
     page/Console.cpp
     page/ContentSecurityPolicy.cpp
     page/ContextMenuController.cpp
+    page/Crypto.cpp
     page/DOMSelection.cpp
     page/DOMTimer.cpp
     page/DOMWindow.cpp
index 28a8fe8..73ed99b 100644 (file)
@@ -1,3 +1,42 @@
+2011-02-10  Adam Barth  <abarth@webkit.org>
+
+        Reviewed by Eric Seidel.
+
+        WebKit should have a cryptographic RNG
+        https://bugs.webkit.org/show_bug.cgi?id=22049
+
+        Add crypto.getRandomValues.  Yes, all these diffs are required to
+        expose a single function to the DOM.
+
+        Test: security/crypto-random-values.html
+
+        * Android.mk:
+        * CMakeLists.txt:
+        * DerivedSources.cpp:
+        * DerivedSources.make:
+        * ForwardingHeaders/wtf/CryptographicallyRandomNumber.h: Added.
+        * GNUmakefile.am:
+        * WebCore.gypi:
+        * WebCore.pri:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSDOMWindowCustom.cpp:
+        * bindings/v8/custom/V8DOMWindowCustom.cpp:
+        * config.h:
+        * page/Crypto.cpp: Added.
+        (WebCore::Crypto::Crypto):
+        (WebCore::Crypto::getRandomValues):
+        * page/Crypto.h: Added.
+        (WebCore::Crypto::create):
+        * page/Crypto.idl: Added.
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::clear):
+        (WebCore::DOMWindow::crypto):
+        * page/DOMWindow.h:
+        (WebCore::DOMWindow::optionalCrypto):
+        * page/DOMWindow.idl:
+
 2011-02-11  Ryuan Choi  <ryuan.choi@samsung.com>
 
         Unreviewed build fix.
index 1734f02..b47d815 100644 (file)
@@ -50,6 +50,7 @@
 #include "JSConsole.cpp"
 #include "JSCoordinates.cpp"
 #include "JSCounter.cpp"
+#include "JSCrypto.cpp"
 #include "JSCSSCharsetRule.cpp"
 #include "JSCSSFontFaceRule.cpp"
 #include "JSCSSImportRule.cpp"
index 40bbd7f..3ead1c7 100644 (file)
@@ -127,6 +127,7 @@ DOM_CLASSES = \
     Console \
     Coordinates \
     Counter \
+    Crypto \
     CustomEvent \
     DataGridColumn \
     DataGridColumnList \
diff --git a/Source/WebCore/ForwardingHeaders/wtf/CryptographicallyRandomNumber.h b/Source/WebCore/ForwardingHeaders/wtf/CryptographicallyRandomNumber.h
new file mode 100644 (file)
index 0000000..6c36f9b
--- /dev/null
@@ -0,0 +1,5 @@
+#ifndef WebCore_FWD_CryptographicallyRandomNumber_h
+#define WebCore_FWD_CryptographicallyRandomNumber_h
+#include <JavaScriptCore/CryptographicallyRandomNumber.h>
+#endif
+
index dcc44a4..4c3788b 100644 (file)
@@ -162,6 +162,8 @@ webcore_built_sources += \
        DerivedSources/WebCore/JSCoordinates.h \
        DerivedSources/WebCore/JSCounter.cpp \
        DerivedSources/WebCore/JSCounter.h \
+       DerivedSources/WebCore/JSCrypto.cpp \
+       DerivedSources/WebCore/JSCrypto.h \
        DerivedSources/WebCore/JSCSSCharsetRule.cpp \
        DerivedSources/WebCore/JSCSSCharsetRule.h \
        DerivedSources/WebCore/JSCSSFontFaceRule.cpp \
@@ -2173,9 +2175,9 @@ webcore_sources += \
        Source/WebCore/page/animation/KeyframeAnimation.h \
        Source/WebCore/page/BarInfo.cpp \
        Source/WebCore/page/BarInfo.h \
-       Source/WebCore/page/ChromeClient.h \
        Source/WebCore/page/Chrome.cpp \
        Source/WebCore/page/Chrome.h \
+       Source/WebCore/page/ChromeClient.h \
        Source/WebCore/page/Console.cpp \
        Source/WebCore/page/Console.h \
        Source/WebCore/page/ContentSecurityPolicy.cpp \
@@ -2185,6 +2187,8 @@ webcore_sources += \
        Source/WebCore/page/ContextMenuController.h \
        Source/WebCore/page/ContextMenuProvider.h \
        Source/WebCore/page/Coordinates.h \
+       Source/WebCore/page/Crypto.cpp \
+       Source/WebCore/page/Crypto.h \
        Source/WebCore/page/DOMSelection.cpp \
        Source/WebCore/page/DOMSelection.h \
        Source/WebCore/page/DOMTimer.cpp \
@@ -2213,9 +2217,9 @@ webcore_sources += \
        Source/WebCore/page/Geolocation.cpp \
        Source/WebCore/page/Geolocation.h \
        Source/WebCore/page/GeolocationClient.h \
-       Source/WebCore/page/GeolocationError.h \
        Source/WebCore/page/GeolocationController.cpp \
        Source/WebCore/page/GeolocationController.h \
+       Source/WebCore/page/GeolocationError.h \
        Source/WebCore/page/GeolocationPosition.h \
        Source/WebCore/page/GeolocationPositionCache.cpp \
        Source/WebCore/page/GeolocationPositionCache.h \
@@ -2232,30 +2236,30 @@ webcore_sources += \
        Source/WebCore/page/MemoryInfo.h \
        Source/WebCore/page/MouseEventWithHitTestResults.cpp \
        Source/WebCore/page/MouseEventWithHitTestResults.h \
-       Source/WebCore/page/NavigatorBase.cpp \
-       Source/WebCore/page/NavigatorBase.h \
        Source/WebCore/page/Navigator.cpp \
        Source/WebCore/page/Navigator.h \
+       Source/WebCore/page/NavigatorBase.cpp \
+       Source/WebCore/page/NavigatorBase.h \
        Source/WebCore/page/OriginAccessEntry.cpp \
        Source/WebCore/page/OriginAccessEntry.h \
        Source/WebCore/page/Page.cpp \
+       Source/WebCore/page/Page.h \
        Source/WebCore/page/PageGroup.cpp \
        Source/WebCore/page/PageGroup.h \
        Source/WebCore/page/PageGroupLoadDeferrer.cpp \
        Source/WebCore/page/PageGroupLoadDeferrer.h \
-       Source/WebCore/page/Page.h \
        Source/WebCore/page/Performance.cpp \
        Source/WebCore/page/Performance.h \
        Source/WebCore/page/PerformanceNavigation.cpp \
        Source/WebCore/page/PerformanceNavigation.h \
        Source/WebCore/page/PerformanceTiming.cpp \
        Source/WebCore/page/PerformanceTiming.h \
-       Source/WebCore/page/PluginHalterClient.h \
        Source/WebCore/page/PluginHalter.cpp \
        Source/WebCore/page/PluginHalter.h \
+       Source/WebCore/page/PluginHalterClient.h \
        Source/WebCore/page/PositionCallback.h \
-       Source/WebCore/page/PositionErrorCallback.h \
        Source/WebCore/page/PositionError.h \
+       Source/WebCore/page/PositionErrorCallback.h \
        Source/WebCore/page/PositionOptions.h \
        Source/WebCore/page/PrintContext.cpp \
        Source/WebCore/page/PrintContext.h \
index ca7b29e..eb8016c 100644 (file)
             'page/BarInfo.idl',
             'page/Console.idl',
             'page/Coordinates.idl',
+            'page/Crypto.idl',
             'page/DOMSelection.idl',
             'page/DOMWindow.idl',
             'page/EventSource.idl',
             'page/ContextMenuController.cpp',
             'page/ContextMenuController.h',
             'page/ContextMenuProvider.h',
+            'page/Crypto.cpp',
+            'page/Crypto.h',
             'page/DOMSelection.cpp',
             'page/DOMSelection.h',
             'page/DOMTimer.cpp',
index 43ea483..52e2738 100644 (file)
@@ -308,6 +308,7 @@ IDL_BINDINGS += \
     page/BarInfo.idl \
     page/Console.idl \
     page/Coordinates.idl \
+    page/Crypto.idl \
     page/DOMSelection.idl \
     page/DOMWindow.idl \
     page/EventSource.idl \
index d2eb91e..d503bb6 100644 (file)
@@ -1128,11 +1128,10 @@ SOURCES += \
     page/Console.cpp \
     page/ContentSecurityPolicy.cpp \
     page/ContextMenuController.cpp \
+    page/Crypto.cpp \
     page/DOMSelection.cpp \
     page/DOMTimer.cpp \
     page/DOMWindow.cpp \
-    page/Navigator.cpp \
-    page/NavigatorBase.cpp \
     page/DragController.cpp \
     page/EventHandler.cpp \
     page/EventSource.cpp \
@@ -1148,6 +1147,8 @@ SOURCES += \
     page/Location.cpp \
     page/MemoryInfo.cpp \
     page/MouseEventWithHitTestResults.cpp \
+    page/Navigator.cpp \
+    page/NavigatorBase.cpp \
     page/OriginAccessEntry.cpp \
     page/Page.cpp \
     page/PageGroup.cpp \
@@ -1157,8 +1158,8 @@ SOURCES += \
     page/PerformanceTiming.cpp \
     page/PluginHalter.cpp \
     page/PrintContext.cpp \
-    page/SecurityOrigin.cpp \
     page/Screen.cpp \
+    page/SecurityOrigin.cpp \
     page/Settings.cpp \
     page/SpatialNavigation.cpp \
     page/SuspendableTimer.cpp \
index 6aa2669..0668a56 100755 (executable)
                                >
                        </File>
                        <File
+                               RelativePath="$(ConfigurationBuildDir)\obj\$(ProjectName)\DerivedSources\JSCrypto.cpp"
+                               >
+                               <FileConfiguration
+                                       Name="Debug|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Release|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Debug_Cairo_CFLite|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Release_Cairo_CFLite|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Debug_All|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Release_LTCG|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                       </File>
+                       <File
+                               RelativePath="$(ConfigurationBuildDir)\obj\$(ProjectName)\DerivedSources\JSCrypto.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="$(ConfigurationBuildDir)\obj\$(ProjectName)\DerivedSources\JSCSSCharsetRule.cpp"
                                >
                                <FileConfiguration
index cac4355..fc17927 100644 (file)
                973889A1116EA9DC00ADF313 /* DocumentWriter.h in Headers */ = {isa = PBXBuildFile; fileRef = 9738899F116EA9DC00ADF313 /* DocumentWriter.h */; settings = {ATTRIBUTES = (Private, ); }; };
                973E325610883B7C005BC493 /* ResourceLoadNotifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 973E325410883B7C005BC493 /* ResourceLoadNotifier.cpp */; };
                973E325710883B7C005BC493 /* ResourceLoadNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 973E325510883B7C005BC493 /* ResourceLoadNotifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               975CA28A130365F800E99AD9 /* Crypto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 975CA287130365F800E99AD9 /* Crypto.cpp */; };
+               975CA28B130365F800E99AD9 /* Crypto.h in Headers */ = {isa = PBXBuildFile; fileRef = 975CA288130365F800E99AD9 /* Crypto.h */; };
+               975CA2A11303679D00E99AD9 /* JSCrypto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 975CA29F1303679D00E99AD9 /* JSCrypto.cpp */; };
+               975CA2A21303679D00E99AD9 /* JSCrypto.h in Headers */ = {isa = PBXBuildFile; fileRef = 975CA2A01303679D00E99AD9 /* JSCrypto.h */; };
                976D6C77122B8A3D001FD1F7 /* AsyncFileWriter.h in Headers */ = {isa = PBXBuildFile; fileRef = 976D6C58122B8A3D001FD1F7 /* AsyncFileWriter.h */; };
                976D6C78122B8A3D001FD1F7 /* Blob.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 976D6C59122B8A3D001FD1F7 /* Blob.cpp */; };
                976D6C79122B8A3D001FD1F7 /* Blob.h in Headers */ = {isa = PBXBuildFile; fileRef = 976D6C5A122B8A3D001FD1F7 /* Blob.h */; };
                9738899F116EA9DC00ADF313 /* DocumentWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentWriter.h; sourceTree = "<group>"; };
                973E325410883B7C005BC493 /* ResourceLoadNotifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceLoadNotifier.cpp; sourceTree = "<group>"; };
                973E325510883B7C005BC493 /* ResourceLoadNotifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoadNotifier.h; sourceTree = "<group>"; };
+               975CA287130365F800E99AD9 /* Crypto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Crypto.cpp; sourceTree = "<group>"; };
+               975CA288130365F800E99AD9 /* Crypto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Crypto.h; sourceTree = "<group>"; };
+               975CA289130365F800E99AD9 /* Crypto.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Crypto.idl; sourceTree = "<group>"; };
+               975CA29F1303679D00E99AD9 /* JSCrypto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCrypto.cpp; sourceTree = "<group>"; };
+               975CA2A01303679D00E99AD9 /* JSCrypto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCrypto.h; sourceTree = "<group>"; };
                976D6C58122B8A3D001FD1F7 /* AsyncFileWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AsyncFileWriter.h; path = fileapi/AsyncFileWriter.h; sourceTree = "<group>"; };
                976D6C59122B8A3D001FD1F7 /* Blob.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Blob.cpp; path = fileapi/Blob.cpp; sourceTree = "<group>"; };
                976D6C5A122B8A3D001FD1F7 /* Blob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Blob.h; path = fileapi/Blob.h; sourceTree = "<group>"; };
                                7ADE722510CBBB9B006B3B3A /* ContextMenuProvider.h */,
                                FE6FD4850F676E5700092873 /* Coordinates.h */,
                                FE6FD4860F676E5700092873 /* Coordinates.idl */,
+                               975CA287130365F800E99AD9 /* Crypto.cpp */,
+                               975CA288130365F800E99AD9 /* Crypto.h */,
+                               975CA289130365F800E99AD9 /* Crypto.idl */,
                                BC5A86810C33676000EEA649 /* DOMSelection.cpp */,
                                BC5A86820C33676000EEA649 /* DOMSelection.h */,
                                BC5A86830C33676000EEA649 /* DOMSelection.idl */,
                                BC124EFE0C26447A009E2349 /* JSBarInfo.h */,
                                BC98543B0CD3D98B00069BC1 /* JSConsole.cpp */,
                                BC98543C0CD3D98B00069BC1 /* JSConsole.h */,
+                               975CA29F1303679D00E99AD9 /* JSCrypto.cpp */,
+                               975CA2A01303679D00E99AD9 /* JSCrypto.h */,
                                BC5A86B30C3367E800EEA649 /* JSDOMSelection.cpp */,
                                BC5A86B40C3367E800EEA649 /* JSDOMSelection.h */,
                                1403BA0B09EB18C700797C7F /* JSDOMWindow.cpp */,
                                E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */,
                                9343CB8212F25E510033C5EE /* TextCodecUTF8.h in Headers */,
                                977E2E0F12F0FC9C00C13379 /* XSSFilter.h in Headers */,
+                               975CA28B130365F800E99AD9 /* Crypto.h in Headers */,
+                               975CA2A21303679D00E99AD9 /* JSCrypto.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                9343CB8112F25E510033C5EE /* TextCodecUTF8.cpp in Sources */,
                                977E2E0E12F0FC9C00C13379 /* XSSFilter.cpp in Sources */,
                                0F29C16E1300C2E2002D794E /* AccessibilityAllInOne.cpp in Sources */,
+                               975CA28A130365F800E99AD9 /* Crypto.cpp in Sources */,
+                               975CA2A11303679D00E99AD9 /* JSCrypto.cpp in Sources */,
                                A1E1154413015C3D0054AC8C /* DistantLightSource.cpp in Sources */,
                                A1E1154613015C4E0054AC8C /* PointLightSource.cpp in Sources */,
                                A1E1154813015C5D0054AC8C /* SpotLightSource.cpp in Sources */,
index 25f95fa..87fa950 100644 (file)
@@ -489,11 +489,6 @@ void JSDOMWindow::setLocation(ExecState* exec, JSValue value)
     impl()->setLocation(ustringToString(locationString), activeDOMWindow(exec), firstDOMWindow(exec));
 }
 
-JSValue JSDOMWindow::crypto(ExecState*) const
-{
-    return jsUndefined();
-}
-
 JSValue JSDOMWindow::event(ExecState* exec) const
 {
     Event* event = currentEvent();
index 328a9c1..85ae322 100644 (file)
@@ -183,12 +183,6 @@ void V8DOMWindow::eventAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::
     context->Global()->SetHiddenValue(eventSymbol, value);
 }
 
-v8::Handle<v8::Value> V8DOMWindow::cryptoAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
-{
-    // FIXME: Implement me.
-    return v8::Undefined();
-}
-
 void V8DOMWindow::locationAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
 {
     DOMWindow* imp = V8DOMWindow::toNative(info.Holder());
index 4d5c8fa..896556f 100644 (file)
 #define USE_SYSTEM_MALLOC 1
 #endif
 
+#if OS(DARWIN) || OS(UNIX) || OS(WINDOWS)
+#define WTF_USE_OS_RANDOMNESS 1
+#endif
+
 #if PLATFORM(CHROMIUM)
 
 #if !OS(DARWIN)
diff --git a/Source/WebCore/page/Crypto.cpp b/Source/WebCore/page/Crypto.cpp
new file mode 100644 (file)
index 0000000..0b1795e
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Google, Inc. ("Google") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY GOOGLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "config.h"
+#include "Crypto.h"
+
+#include "ExceptionCode.h"
+#include "Uint8Array.h"
+#include <wtf/CryptographicallyRandomNumber.h>
+
+
+namespace WebCore {
+
+Crypto::Crypto()
+{
+}
+
+void Crypto::getRandomValues(ArrayBufferView* array, ExceptionCode& ec)
+{
+#if USE(OS_RANDOMNESS)
+    if (!array || !array->isUnsignedByteArray()) {
+        ec = VALIDATION_ERR;
+        return;
+    }
+    cryptographicallyRandomValues(array->baseAddress(), array->byteLength());
+#else
+    ASSERT_UNUSED(array, array);
+    ec = NOT_SUPPORTED_ERR;
+#endif
+}
+
+}
diff --git a/Source/WebCore/page/Crypto.h b/Source/WebCore/page/Crypto.h
new file mode 100644 (file)
index 0000000..bcccd7e
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Google, Inc. ("Google") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY GOOGLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef Crypto_h
+#define Crypto_h
+
+#include <wtf/Forward.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class ArrayBufferView;
+
+typedef int ExceptionCode;
+
+class Crypto : public RefCounted<Crypto> {
+public:
+    static PassRefPtr<Crypto> create() { return adoptRef(new Crypto()); }
+
+    void getRandomValues(ArrayBufferView*, ExceptionCode&);
+
+private:
+    Crypto();
+};
+
+}
+
+#endif
diff --git a/Source/WebCore/page/Crypto.idl b/Source/WebCore/page/Crypto.idl
new file mode 100644 (file)
index 0000000..b4e8f61
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Googl, Inc. ("Google") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY GOOGLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module window {
+
+    interface [
+        OmitConstructor
+    ] Crypto {
+        // FIXME: We should just enable ArrayBuffer support all the time.
+        [Conditional=WEBGL|BLOB] void getRandomValues(in ArrayBufferView array) raises(DOMException);
+    };
+
+}
index 575319b..560af91 100644 (file)
@@ -37,6 +37,7 @@
 #include "CSSStyleSelector.h"
 #include "Chrome.h"
 #include "Console.h"
+#include "Crypto.h"
 #include "DOMApplicationCache.h"
 #include "DOMSelection.h"
 #include "DOMSettableTokenList.h"
@@ -433,6 +434,8 @@ void DOMWindow::clear()
         m_history->disconnectFrame();
     m_history = 0;
 
+    m_crypto = 0;
+
     if (m_locationbar)
         m_locationbar->disconnectFrame();
     m_locationbar = 0;
@@ -530,6 +533,13 @@ History* DOMWindow::history() const
     return m_history.get();
 }
 
+Crypto* DOMWindow::crypto() const
+{
+    if (!m_crypto)
+        m_crypto = Crypto::create();
+    return m_crypto.get();
+}
+
 BarInfo* DOMWindow::locationbar() const
 {
     if (!m_locationbar)
index a1e4462..058165f 100644 (file)
@@ -37,6 +37,7 @@ namespace WebCore {
     class CSSRuleList;
     class CSSStyleDeclaration;
     class Console;
+    class Crypto;
     class DOMApplicationCache;
     class DOMSelection;
     class DOMURL;
@@ -114,6 +115,7 @@ namespace WebCore {
 
         Screen* screen() const;
         History* history() const;
+        Crypto* crypto() const;
         BarInfo* locationbar() const;
         BarInfo* menubar() const;
         BarInfo* personalbar() const;
@@ -340,6 +342,7 @@ namespace WebCore {
         Screen* optionalScreen() const { return m_screen.get(); }
         DOMSelection* optionalSelection() const { return m_selection.get(); }
         History* optionalHistory() const { return m_history.get(); }
+        Crypto* optionalCrypto() const { return m_crypto.get(); }
         BarInfo* optionalLocationbar() const { return m_locationbar.get(); }
         BarInfo* optionalMenubar() const { return m_menubar.get(); }
         BarInfo* optionalPersonalbar() const { return m_personalbar.get(); }
@@ -441,6 +444,7 @@ namespace WebCore {
         mutable RefPtr<Screen> m_screen;
         mutable RefPtr<DOMSelection> m_selection;
         mutable RefPtr<History> m_history;
+        mutable RefPtr<Crypto>  m_crypto;
         mutable RefPtr<BarInfo> m_locationbar;
         mutable RefPtr<BarInfo> m_menubar;
         mutable RefPtr<BarInfo> m_personalbar;
index 26ff6d6..7c84306 100644 (file)
@@ -58,7 +58,7 @@ module window {
 
         attribute [Replaceable, CustomGetter, V8CustomSetter] Event event;
 
-        readonly attribute [Custom] Crypto crypto;
+        readonly attribute Crypto crypto;
 
         DOMSelection getSelection();