1/* 2 * Copyright (C) 2010 Google Inc. All rights reserved. 3 * Copyright (C) 2012 Intel Inc. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * * Redistributions in binary form must reproduce the above 12 * copyright notice, this list of conditions and the following disclaimer 13 * in the documentation and/or other materials provided with the 14 * distribution. 15 * * Neither the name of Google Inc. nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#ifndef Performance_h 33#define Performance_h 34 35#if ENABLE(WEB_TIMING) 36 37#include "DOMWindowProperty.h" 38#include "EventTarget.h" 39#include "PerformanceEntryList.h" 40#include "PerformanceNavigation.h" 41#include "PerformanceTiming.h" 42#include "ScriptWrappable.h" 43#include <wtf/PassRefPtr.h> 44#include <wtf/RefCounted.h> 45#include <wtf/RefPtr.h> 46#include <wtf/text/WTFString.h> 47 48namespace WebCore { 49 50class Document; 51class ResourceRequest; 52class ResourceResponse; 53class UserTiming; 54 55class Performance : public ScriptWrappable, public RefCounted<Performance>, public DOMWindowProperty, public EventTarget { 56public: 57 static PassRefPtr<Performance> create(Frame* frame) { return adoptRef(new Performance(frame)); } 58 ~Performance(); 59 60 virtual const AtomicString& interfaceName() const; 61 virtual ScriptExecutionContext* scriptExecutionContext() const; 62 63 PerformanceNavigation* navigation() const; 64 PerformanceTiming* timing() const; 65 double now() const; 66 67#if ENABLE(PERFORMANCE_TIMELINE) 68 PassRefPtr<PerformanceEntryList> webkitGetEntries() const; 69 PassRefPtr<PerformanceEntryList> webkitGetEntriesByType(const String& entryType); 70 PassRefPtr<PerformanceEntryList> webkitGetEntriesByName(const String& name, const String& entryType); 71#endif 72 73#if ENABLE(RESOURCE_TIMING) 74 void webkitClearResourceTimings(); 75 void webkitSetResourceTimingBufferSize(unsigned int); 76 77 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitresourcetimingbufferfull); 78 79 void addResourceTiming(const String& initiatorName, Document*, const ResourceRequest&, const ResourceResponse&, double initiationTime, double finishTime); 80#endif 81 82 using RefCounted<Performance>::ref; 83 using RefCounted<Performance>::deref; 84 85#if ENABLE(USER_TIMING) 86 void webkitMark(const String& markName, ExceptionCode&); 87 void webkitClearMarks(const String& markName); 88 89 void webkitMeasure(const String& measureName, const String& startMark, const String& endMark, ExceptionCode&); 90 void webkitClearMeasures(const String& measureName); 91#endif // ENABLE(USER_TIMING) 92 93private: 94 explicit Performance(Frame*); 95 96 virtual void refEventTarget() { ref(); } 97 virtual void derefEventTarget() { deref(); } 98 virtual EventTargetData* eventTargetData(); 99 virtual EventTargetData* ensureEventTargetData(); 100 bool isResourceTimingBufferFull(); 101 102 EventTargetData m_eventTargetData; 103 104 mutable RefPtr<PerformanceNavigation> m_navigation; 105 mutable RefPtr<PerformanceTiming> m_timing; 106 107#if ENABLE(RESOURCE_TIMING) 108 Vector<RefPtr<PerformanceEntry> > m_resourceTimingBuffer; 109 unsigned m_resourceTimingBufferSize; 110#endif 111 112#if ENABLE(USER_TIMING) 113 RefPtr<UserTiming> m_userTiming; 114#endif // ENABLE(USER_TIMING) 115}; 116 117} 118 119#endif // ENABLE(WEB_TIMING) 120 121#endif // Performance_h 122