Bug 539095 - Expose high-res timers to web content (performance.now()). r=bz, sr=smaug

--HG--
extra : transplant_source : o%9F%061%D4%B5%7D%5C%FB%95%5D%16%27%DEKU%EC%21%3AR
This commit is contained in:
Gijs Kruitbosch 2012-04-27 09:22:06 +02:00
parent 04cb76033f
commit ae54e2bc78
7 changed files with 48 additions and 2 deletions

View File

@ -95,6 +95,12 @@ public:
nsresult TimeStampToDOMOrFetchStart(mozilla::TimeStamp aStamp,
DOMTimeMilliSec* aResult);
inline DOMHighResTimeStamp TimeStampToDOMHighRes(mozilla::TimeStamp aStamp)
{
mozilla::TimeDuration duration = aStamp - mNavigationStartTimeStamp;
return duration.ToMilliseconds();
}
private:
nsDOMNavigationTiming(const nsDOMNavigationTiming &){};
~nsDOMNavigationTiming();

View File

@ -319,3 +319,11 @@ nsPerformance::GetNavigation(nsIDOMPerformanceNavigation** aNavigation)
NS_IF_ADDREF(*aNavigation = mNavigation);
return NS_OK;
}
NS_IMETHODIMP
nsPerformance::Now(DOMHighResTimeStamp* aNow)
{
*aNow = mDOMTiming->TimeStampToDOMHighRes(mozilla::TimeStamp::Now());
return NS_OK;
}

View File

@ -47,6 +47,7 @@ class nsWrapperCache;
typedef unsigned long long DOMTimeStamp;
typedef unsigned long long DOMTimeMilliSec;
typedef double DOMHighResTimeStamp;
// Core
interface nsIDOMAttr;

View File

@ -37,14 +37,16 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
#include "domstubs.idl"
interface nsIDOMPerformanceTiming;
interface nsIDOMPerformanceNavigation;
[scriptable, uuid(446faf26-000b-4e66-a5fd-ae37c5ed6beb)]
[scriptable, uuid(ac274ec8-ee9f-44ef-b2f0-b13c22225a98)]
interface nsIDOMPerformance : nsISupports
{
readonly attribute nsIDOMPerformanceTiming timing;
readonly attribute nsIDOMPerformanceNavigation navigation;
DOMHighResTimeStamp now();
};

View File

@ -76,6 +76,7 @@ _TEST_FILES = \
test_focus_legend_noparent.html \
file_clonewrapper.html \
file_moving_nodeList.html \
test_performance_now.html \
$(NULL)
_CHROME_FILES = \

View File

@ -0,0 +1,23 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for High Resolution Timer</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script>
ok(window.performance);
ok(typeof window.performance.now == 'function');
var n = window.performance.now();
ok(n >= 0);
ok(window.performance.now() >= n);
SimpleTest.waitForExplicitFinish();
setTimeout(function() {
ok(window.performance.now() > n);
SimpleTest.finish();
}, 20);
</script>
</body>
</html>

View File

@ -468,6 +468,11 @@ members = [
'nsIIndexedDatabaseUsageCallback.*',
'nsIIndexedDatabaseManager.*',
# Performance
'nsIDOMPerformance.*',
'nsIDOMPerformanceTiming.*',
'nsIDOMPerformanceNavigation.*',
'nsIDOMDOMError.*',
]