Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Intel Inc. All rights reserved. | 3 * Copyright (C) 2012 Intel Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 #include "config.h" | 32 #include "config.h" |
| 33 #include "core/page/Performance.h" | 33 #include "core/page/Performance.h" |
| 34 | 34 |
| 35 #include "bindings/v8/ScriptFunctionCall.h" | |
| 35 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 36 #include "core/loader/DocumentLoader.h" | 37 #include "core/loader/DocumentLoader.h" |
| 37 #include "core/page/MemoryInfo.h" | 38 #include "core/page/MemoryInfo.h" |
| 38 #include "core/page/PerformanceEntry.h" | 39 #include "core/page/PerformanceEntry.h" |
| 39 #include "core/page/PerformanceNavigation.h" | 40 #include "core/page/PerformanceNavigation.h" |
| 40 #include "core/page/PerformanceResourceTiming.h" | 41 #include "core/page/PerformanceResourceTiming.h" |
| 41 #include "core/page/PerformanceTiming.h" | 42 #include "core/page/PerformanceTiming.h" |
| 42 #include "core/page/PerformanceUserTiming.h" | 43 #include "core/page/PerformanceUserTiming.h" |
| 43 #include <wtf/CurrentTime.h> | 44 #include <wtf/CurrentTime.h> |
| 44 | 45 |
| 45 #include "core/page/Frame.h" | 46 #include "core/page/Frame.h" |
| 46 | 47 |
| 47 namespace WebCore { | 48 namespace WebCore { |
| 48 | 49 |
| 49 static const size_t defaultResourceTimingBufferSize = 150; | 50 static const size_t defaultResourceTimingBufferSize = 150; |
| 50 | 51 |
| 51 Performance::Performance(Frame* frame) | 52 Performance::Performance(Frame* frame) |
| 52 : DOMWindowProperty(frame) | 53 : DOMWindowProperty(frame) |
| 53 , m_resourceTimingBufferSize(defaultResourceTimingBufferSize) | 54 , m_resourceTimingBufferSize(defaultResourceTimingBufferSize) |
| 54 , m_userTiming(0) | 55 , m_userTiming(0) |
| 56 , m_onwebkitresourcetimingbufferfull(v8::Null()) | |
| 55 { | 57 { |
| 56 ScriptWrappable::init(this); | 58 ScriptWrappable::init(this); |
| 57 } | 59 } |
| 58 | 60 |
| 59 Performance::~Performance() | 61 Performance::~Performance() |
| 60 { | 62 { |
| 61 } | 63 } |
| 62 | 64 |
| 63 const AtomicString& Performance::interfaceName() const | |
| 64 { | |
| 65 return eventNames().interfaceForPerformance; | |
| 66 } | |
| 67 | |
| 68 ScriptExecutionContext* Performance::scriptExecutionContext() const | |
| 69 { | |
| 70 if (!frame()) | |
| 71 return 0; | |
| 72 return frame()->document(); | |
| 73 } | |
| 74 | |
| 75 PassRefPtr<MemoryInfo> Performance::memory() const | 65 PassRefPtr<MemoryInfo> Performance::memory() const |
| 76 { | 66 { |
| 77 return MemoryInfo::create(m_frame); | 67 return MemoryInfo::create(m_frame); |
| 78 } | 68 } |
| 79 | 69 |
| 80 PerformanceNavigation* Performance::navigation() const | 70 PerformanceNavigation* Performance::navigation() const |
| 81 { | 71 { |
| 82 if (!m_navigation) | 72 if (!m_navigation) |
| 83 m_navigation = PerformanceNavigation::create(m_frame); | 73 m_navigation = PerformanceNavigation::create(m_frame); |
| 84 | 74 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 | 135 |
| 146 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare LessThan); | 136 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare LessThan); |
| 147 return entries; | 137 return entries; |
| 148 } | 138 } |
| 149 | 139 |
| 150 void Performance::webkitClearResourceTimings() | 140 void Performance::webkitClearResourceTimings() |
| 151 { | 141 { |
| 152 m_resourceTimingBuffer.clear(); | 142 m_resourceTimingBuffer.clear(); |
| 153 } | 143 } |
| 154 | 144 |
| 155 void Performance::webkitSetResourceTimingBufferSize(unsigned size) | 145 void Performance::callResourceTimingBufferFullCallback(ScriptState* scriptState) |
| 146 { | |
| 147 if (!scriptState || m_onwebkitresourcetimingbufferfull.isNull()) | |
| 148 return; | |
| 149 | |
| 150 v8::HandleScope handleScope; | |
| 151 ScriptCallback callback(scriptState, m_onwebkitresourcetimingbufferfull); | |
| 152 v8::Handle<v8::Context> context = scriptState->context(); | |
| 153 if (context.IsEmpty()) | |
| 154 return; | |
| 155 | |
| 156 v8::Context::Scope scope(context); | |
| 157 callback.call(); | |
| 158 } | |
| 159 | |
| 160 void Performance::webkitSetResourceTimingBufferSize(ScriptState* scriptState, un signed size) | |
| 156 { | 161 { |
| 157 m_resourceTimingBufferSize = size; | 162 m_resourceTimingBufferSize = size; |
| 158 if (isResourceTimingBufferFull()) | 163 if (isResourceTimingBufferFull()) |
| 159 dispatchEvent(Event::create(eventNames().webkitresourcetimingbufferfullE vent, false, false)); | 164 callResourceTimingBufferFullCallback(scriptState); |
| 165 } | |
| 166 | |
| 167 void Performance::setOnwebkitresourcetimingbufferfull(const ScriptValue& callbac k) | |
| 168 { | |
| 169 if (callback.isNull() || callback.isUndefined()) { | |
| 170 m_onwebkitresourcetimingbufferfull = ScriptValue(v8::Null()); | |
| 171 return; | |
| 172 } | |
| 173 | |
| 174 if (!callback.isFunction()) | |
|
arv (Not doing code reviews)
2013/07/09 18:19:58
This is a bit inconsistent.
WebIDL says throw a T
| |
| 175 return; | |
| 176 | |
| 177 m_onwebkitresourcetimingbufferfull = callback; | |
| 160 } | 178 } |
| 161 | 179 |
| 162 void Performance::addResourceTiming(const String& initiatorName, Document* initi atorDocument, const ResourceRequest& request, const ResourceResponse& response, double initiationTime, double finishTime) | 180 void Performance::addResourceTiming(const String& initiatorName, Document* initi atorDocument, const ResourceRequest& request, const ResourceResponse& response, double initiationTime, double finishTime) |
| 163 { | 181 { |
| 164 if (isResourceTimingBufferFull()) | 182 if (isResourceTimingBufferFull()) |
| 165 return; | 183 return; |
| 166 | 184 |
| 167 RefPtr<PerformanceEntry> entry = PerformanceResourceTiming::create(initiator Name, request, response, initiationTime, finishTime, initiatorDocument); | 185 RefPtr<PerformanceEntry> entry = PerformanceResourceTiming::create(initiator Name, request, response, initiationTime, finishTime, initiatorDocument); |
| 168 | 186 |
| 169 m_resourceTimingBuffer.append(entry); | 187 m_resourceTimingBuffer.append(entry); |
| 170 | 188 |
| 171 if (isResourceTimingBufferFull()) | 189 if (isResourceTimingBufferFull()) |
| 172 dispatchEvent(Event::create(eventNames().webkitresourcetimingbufferfullE vent, false, false)); | 190 callResourceTimingBufferFullCallback(mainWorldScriptState(frame())); |
| 173 } | 191 } |
| 174 | 192 |
| 175 bool Performance::isResourceTimingBufferFull() | 193 bool Performance::isResourceTimingBufferFull() |
| 176 { | 194 { |
| 177 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; | 195 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; |
| 178 } | 196 } |
| 179 | 197 |
| 180 EventTargetData* Performance::eventTargetData() | |
| 181 { | |
| 182 return &m_eventTargetData; | |
| 183 } | |
| 184 | |
| 185 EventTargetData* Performance::ensureEventTargetData() | |
| 186 { | |
| 187 return &m_eventTargetData; | |
| 188 } | |
| 189 | |
| 190 void Performance::mark(const String& markName, ExceptionCode& ec) | 198 void Performance::mark(const String& markName, ExceptionCode& ec) |
| 191 { | 199 { |
| 192 ec = 0; | 200 ec = 0; |
| 193 if (!m_userTiming) | 201 if (!m_userTiming) |
| 194 m_userTiming = UserTiming::create(this); | 202 m_userTiming = UserTiming::create(this); |
| 195 m_userTiming->mark(markName, ec); | 203 m_userTiming->mark(markName, ec); |
| 196 } | 204 } |
| 197 | 205 |
| 198 void Performance::clearMarks(const String& markName) | 206 void Performance::clearMarks(const String& markName) |
| 199 { | 207 { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 216 m_userTiming = UserTiming::create(this); | 224 m_userTiming = UserTiming::create(this); |
| 217 m_userTiming->clearMeasures(measureName); | 225 m_userTiming->clearMeasures(measureName); |
| 218 } | 226 } |
| 219 | 227 |
| 220 double Performance::now() const | 228 double Performance::now() const |
| 221 { | 229 { |
| 222 return 1000.0 * m_frame->document()->loader()->timing()->monotonicTimeToZero BasedDocumentTime(monotonicallyIncreasingTime()); | 230 return 1000.0 * m_frame->document()->loader()->timing()->monotonicTimeToZero BasedDocumentTime(monotonicallyIncreasingTime()); |
| 223 } | 231 } |
| 224 | 232 |
| 225 } // namespace WebCore | 233 } // namespace WebCore |
| OLD | NEW |