Home | History | Annotate | Download | only in page
      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 #include "bindings/v8/ScriptWrappable.h"
     36 #include "core/dom/EventTarget.h"
     37 #include "core/page/DOMWindowProperty.h"
     38 #include "core/page/MemoryInfo.h"
     39 #include "core/page/PerformanceEntry.h"
     40 #include "core/page/PerformanceNavigation.h"
     41 #include "core/page/PerformanceTiming.h"
     42 #include "wtf/PassRefPtr.h"
     43 #include "wtf/RefCounted.h"
     44 #include "wtf/RefPtr.h"
     45 #include "wtf/text/WTFString.h"
     46 
     47 namespace WebCore {
     48 
     49 class Document;
     50 class ExceptionState;
     51 class ResourceRequest;
     52 class ResourceResponse;
     53 class ResourceTimingInfo;
     54 class UserTiming;
     55 
     56 class Performance : public ScriptWrappable, public RefCounted<Performance>, public DOMWindowProperty, public EventTarget {
     57 public:
     58     static PassRefPtr<Performance> create(Frame* frame) { return adoptRef(new Performance(frame)); }
     59     ~Performance();
     60 
     61     virtual const AtomicString& interfaceName() const;
     62     virtual ScriptExecutionContext* scriptExecutionContext() const;
     63 
     64     PassRefPtr<MemoryInfo> memory() const;
     65     PerformanceNavigation* navigation() const;
     66     PerformanceTiming* timing() const;
     67     double now() const;
     68 
     69     Vector<RefPtr<PerformanceEntry> > getEntries() const;
     70     Vector<RefPtr<PerformanceEntry> > getEntriesByType(const String& entryType);
     71     Vector<RefPtr<PerformanceEntry> > getEntriesByName(const String& name, const String& entryType);
     72 
     73     void webkitClearResourceTimings();
     74     void webkitSetResourceTimingBufferSize(unsigned int);
     75 
     76     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitresourcetimingbufferfull);
     77 
     78     void addResourceTiming(const ResourceTimingInfo&, Document*);
     79 
     80     using RefCounted<Performance>::ref;
     81     using RefCounted<Performance>::deref;
     82 
     83     void mark(const String& markName, ExceptionState&);
     84     void clearMarks(const String& markName);
     85 
     86     void measure(const String& measureName, const String& startMark, const String& endMark, ExceptionState&);
     87     void clearMeasures(const String& measureName);
     88 
     89 private:
     90     explicit Performance(Frame*);
     91 
     92     virtual void refEventTarget() { ref(); }
     93     virtual void derefEventTarget() { deref(); }
     94     virtual EventTargetData* eventTargetData();
     95     virtual EventTargetData* ensureEventTargetData();
     96     bool isResourceTimingBufferFull();
     97     void addResourceTimingBuffer(PassRefPtr<PerformanceEntry>);
     98 
     99     EventTargetData m_eventTargetData;
    100 
    101     mutable RefPtr<PerformanceNavigation> m_navigation;
    102     mutable RefPtr<PerformanceTiming> m_timing;
    103 
    104     Vector<RefPtr<PerformanceEntry> > m_resourceTimingBuffer;
    105     unsigned m_resourceTimingBufferSize;
    106     double m_referenceTime;
    107 
    108     RefPtr<UserTiming> m_userTiming;
    109 };
    110 
    111 }
    112 
    113 #endif // Performance_h
    114