Bug 936813 - Implement onresourcetimingbufferfull callback (part 2) r=bz

This commit is contained in:
Valentin Gosu 2014-05-10 05:12:06 +03:00
Родитель 392bd58d88
Коммит b7db64f8c7
6 изменённых файлов: 53 добавлений и 20 удалений

Просмотреть файл

@ -795,6 +795,7 @@ GK_ATOM(onreadystatechange, "onreadystatechange")
GK_ATOM(onreceived, "onreceived")
GK_ATOM(onremoteheld, "onremoteheld")
GK_ATOM(onremoteresumed, "onremoteresumed")
GK_ATOM(onresourcetimingbufferfull, "onresourcetimingbufferfull")
GK_ATOM(onretrieving, "onretrieving")
GK_ATOM(onRequest, "onRequest")
GK_ATOM(onrequestmediaplaystatus, "onrequestmediaplaystatus")

Просмотреть файл

@ -360,18 +360,19 @@ nsPerformanceNavigation::WrapObject(JSContext *cx)
}
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsPerformance,
mWindow, mTiming,
mNavigation, mEntries,
mParentPerformance)
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPerformance)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsPerformance)
NS_IMPL_CYCLE_COLLECTION_INHERITED(nsPerformance, DOMEventTargetHelper,
mWindow, mTiming,
mNavigation, mEntries,
mParentPerformance)
NS_IMPL_ADDREF_INHERITED(nsPerformance, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(nsPerformance, DOMEventTargetHelper)
nsPerformance::nsPerformance(nsIDOMWindow* aWindow,
nsPerformance::nsPerformance(nsPIDOMWindow* aWindow,
nsDOMNavigationTiming* aDOMTiming,
nsITimedChannel* aChannel,
nsPerformance* aParentPerformance)
: mWindow(aWindow),
: DOMEventTargetHelper(aWindow),
mWindow(aWindow),
mDOMTiming(aDOMTiming),
mChannel(aChannel),
mParentPerformance(aParentPerformance),
@ -389,7 +390,7 @@ nsPerformance::~nsPerformance()
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPerformance)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
nsPerformanceTiming*
@ -406,6 +407,21 @@ nsPerformance::Timing()
return mTiming;
}
void
nsPerformance::DispatchBufferFullEvent()
{
nsCOMPtr<nsIDOMEvent> event;
nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr);
if (NS_SUCCEEDED(rv)) {
// it bubbles, and it isn't cancelable
rv = event->InitEvent(NS_LITERAL_STRING("resourcetimingbufferfull"), true, false);
if (NS_SUCCEEDED(rv)) {
event->SetTrusted(true);
DispatchDOMEvent(nullptr, event, nullptr, nullptr);
}
}
}
nsPerformanceNavigation*
nsPerformance::Navigation()
{
@ -543,7 +559,7 @@ nsPerformance::AddEntry(nsIHttpChannel* channel,
PerformanceEntryComparator());
if (mEntries.Length() >= mPrimaryBufferSize) {
// call onresourcetimingbufferfull
// https://bugzilla.mozilla.org/show_bug.cgi?id=936813
DispatchBufferFullEvent();
}
}
}

Просмотреть файл

@ -11,9 +11,10 @@
#include "nsWrapperCache.h"
#include "nsDOMNavigationTiming.h"
#include "nsContentUtils.h"
#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
#include "js/TypeDecls.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/DOMEventTargetHelper.h"
class nsITimedChannel;
class nsPerformance;
@ -254,18 +255,17 @@ private:
};
// Script "performance" object
class nsPerformance MOZ_FINAL : public nsISupports,
public nsWrapperCache
class nsPerformance MOZ_FINAL : public mozilla::DOMEventTargetHelper
{
public:
typedef mozilla::dom::PerformanceEntry PerformanceEntry;
nsPerformance(nsIDOMWindow* aWindow,
nsPerformance(nsPIDOMWindow* aWindow,
nsDOMNavigationTiming* aDOMTiming,
nsITimedChannel* aChannel,
nsPerformance* aParentPerformance);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsPerformance)
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsPerformance, DOMEventTargetHelper)
nsDOMNavigationTiming* GetDOMTiming() const
{
@ -282,7 +282,7 @@ public:
return mParentPerformance;
}
nsIDOMWindow* GetParentObject() const
nsPIDOMWindow* GetParentObject() const
{
return mWindow.get();
}
@ -304,11 +304,13 @@ public:
nsITimedChannel* timedChannel);
void ClearResourceTimings();
void SetResourceTimingBufferSize(uint64_t maxSize);
IMPL_EVENT_HANDLER(resourcetimingbufferfull)
private:
~nsPerformance();
void DispatchBufferFullEvent();
nsCOMPtr<nsIDOMWindow> mWindow;
nsCOMPtr<nsPIDOMWindow> mWindow;
nsRefPtr<nsDOMNavigationTiming> mDOMTiming;
nsCOMPtr<nsITimedChannel> mChannel;
nsRefPtr<nsPerformanceTiming> mTiming;

Просмотреть файл

@ -22,6 +22,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=760851
// get tested as well.
var toTest = [window.performance];
// The event handler has to be initialized or else jsonObj will be undefined
window.performance.onresourcetimingbufferfull = function() {};
function checkAttributesMatch(obj, jsonObj) {
if (typeof(obj) !== "object") {
throw "Expected obj to be of type \"object\". Test failed.";

Просмотреть файл

@ -63,12 +63,19 @@ function isnot(received, notExpected, message) {
window.opener.isnot(received, notExpected, message);
}
var bufferFullCounter = 0;
const expectedBufferFullEvents = 1;
window.onload = function() {
ok(!!window.performance, "Performance object should exist");
ok(!!window.performance.getEntries, "Performance.getEntries() should exist");
ok(!!window.performance.getEntriesByName, "Performance.getEntriesByName() should exist");
ok(!!window.performance.getEntriesByType, "Performance.getEntriesByType() should exist");
window.performance.onresourcetimingbufferfull = function() {
bufferFullCounter += 1;
}
// Here, we should have 6 entries (1 css, 3 png, 1 html) since the image was loaded.
is(window.performance.getEntries().length, 5, "Performance.getEntries() returned wrong number of entries.");
@ -205,6 +212,7 @@ function secondCheck() {
function finishTest() {
// Check if all the tests are completed.
if (iframeTestsDone) {
is(bufferFullCounter, expectedBufferFullEvents, "onresourcetimingbufferfull called a wrong number of times");
window.opener.finishTests();
} else {
mainWindowTestsDone = true;
@ -232,6 +240,7 @@ function checkArraysHaveSameElementsInSameOrder(array1, array2) {
function iframeTestsCompleted() {
if (mainWindowTestsDone) {
is(bufferFullCounter, expectedBufferFullEvents, "onresourcetimingbufferfull called a wrong number of times");
window.opener.finishTests();
}
else {

Просмотреть файл

@ -24,7 +24,7 @@ interface Performance {
jsonifier;
};
// http://www.w3c-test.org/webperf/specs/PerformanceTimeline/#sec-window.performance-attribute
// http://www.w3.org/TR/performance-timeline/#sec-window.performance-attribute
partial interface Performance {
[Pref="dom.enable_resource_timing"]
PerformanceEntryList getEntries();
@ -35,10 +35,12 @@ partial interface Performance {
entryType);
};
// http://w3c-test.org/webperf/specs/ResourceTiming/#extensions-performance-interface
// http://www.w3.org/TR/resource-timing/#extensions-performance-interface
partial interface Performance {
[Pref="dom.enable_resource_timing"]
void clearResourceTimings();
[Pref="dom.enable_resource_timing"]
void setResourceTimingBufferSize(unsigned long maxSize);
[Pref="dom.enable_resource_timing"]
attribute EventHandler onresourcetimingbufferfull;
};