OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/timing/PerformanceNavigationTiming.h" | 5 #include "core/timing/PerformanceNavigationTiming.h" |
6 | 6 |
7 #include "bindings/core/v8/V8ObjectBuilder.h" | 7 #include "bindings/core/v8/V8ObjectBuilder.h" |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/dom/DocumentTiming.h" | 9 #include "core/dom/DocumentTiming.h" |
10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
11 #include "core/loader/DocumentLoadTiming.h" | 11 #include "core/loader/DocumentLoadTiming.h" |
12 #include "core/loader/DocumentLoader.h" | 12 #include "core/loader/DocumentLoader.h" |
13 #include "core/timing/PerformanceBase.h" | 13 #include "core/timing/PerformanceBase.h" |
14 #include "platform/loader/fetch/ResourceTimingInfo.h" | 14 #include "platform/loader/fetch/ResourceTimingInfo.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 PerformanceNavigationTiming::PerformanceNavigationTiming( | 18 PerformanceNavigationTiming::PerformanceNavigationTiming( |
19 LocalFrame* frame, | 19 LocalFrame* frame, |
20 ResourceTimingInfo* info, | 20 ResourceTimingInfo* info, |
21 double timeOrigin) | 21 double timeOrigin) |
22 : PerformanceResourceTiming(info ? info->initialURL().getString() : "", | 22 : PerformanceResourceTiming(info ? info->initialURL().getString() : "", |
23 "navigation", | 23 "navigation", |
24 0.0, | 24 0.0, |
25 0.0), | 25 0.0), |
| 26 ContextClient(frame), |
26 m_timeOrigin(timeOrigin), | 27 m_timeOrigin(timeOrigin), |
27 m_resourceTimingInfo(info), | 28 m_resourceTimingInfo(info) { |
28 m_frame(frame) { | |
29 DCHECK(frame); | 29 DCHECK(frame); |
30 DCHECK(info); | 30 DCHECK(info); |
31 } | 31 } |
32 | 32 |
33 PerformanceNavigationTiming::~PerformanceNavigationTiming() {} | 33 PerformanceNavigationTiming::~PerformanceNavigationTiming() {} |
34 | 34 |
35 DEFINE_TRACE(PerformanceNavigationTiming) { | 35 DEFINE_TRACE(PerformanceNavigationTiming) { |
36 visitor->trace(m_frame); | 36 ContextClient::trace(visitor); |
37 PerformanceEntry::trace(visitor); | 37 PerformanceEntry::trace(visitor); |
38 } | 38 } |
39 | 39 |
40 DocumentLoadTiming* PerformanceNavigationTiming::documentLoadTiming() const { | 40 DocumentLoadTiming* PerformanceNavigationTiming::documentLoadTiming() const { |
41 DocumentLoader* loader = documentLoader(); | 41 DocumentLoader* loader = documentLoader(); |
42 if (!loader) | 42 if (!loader) |
43 return nullptr; | 43 return nullptr; |
44 | 44 |
45 return &loader->timing(); | 45 return &loader->timing(); |
46 } | 46 } |
47 | 47 |
48 DocumentLoader* PerformanceNavigationTiming::documentLoader() const { | 48 DocumentLoader* PerformanceNavigationTiming::documentLoader() const { |
49 return m_frame->loader().documentLoader(); | 49 if (!frame()) |
| 50 return nullptr; |
| 51 return frame()->loader().documentLoader(); |
50 } | 52 } |
51 | 53 |
52 const DocumentTiming* PerformanceNavigationTiming::documentTiming() const { | 54 const DocumentTiming* PerformanceNavigationTiming::documentTiming() const { |
53 Document* document = m_frame->document(); | 55 if (!frame()) |
| 56 return nullptr; |
| 57 Document* document = frame()->document(); |
54 if (!document) | 58 if (!document) |
55 return nullptr; | 59 return nullptr; |
56 | 60 |
57 return &document->timing(); | 61 return &document->timing(); |
58 } | 62 } |
59 | 63 |
60 ResourceLoadTiming* PerformanceNavigationTiming::resourceLoadTiming() const { | 64 ResourceLoadTiming* PerformanceNavigationTiming::resourceLoadTiming() const { |
61 return m_resourceTimingInfo->finalResponse().resourceLoadTiming(); | 65 return m_resourceTimingInfo->finalResponse().resourceLoadTiming(); |
62 } | 66 } |
63 | 67 |
(...skipping 15 matching lines...) Expand all Loading... |
79 | 83 |
80 unsigned long long PerformanceNavigationTiming::getDecodedBodySize() const { | 84 unsigned long long PerformanceNavigationTiming::getDecodedBodySize() const { |
81 return m_resourceTimingInfo->finalResponse().decodedBodyLength(); | 85 return m_resourceTimingInfo->finalResponse().decodedBodyLength(); |
82 } | 86 } |
83 | 87 |
84 AtomicString PerformanceNavigationTiming::initiatorType() const { | 88 AtomicString PerformanceNavigationTiming::initiatorType() const { |
85 return "navigation"; | 89 return "navigation"; |
86 } | 90 } |
87 | 91 |
88 bool PerformanceNavigationTiming::getAllowRedirectDetails() const { | 92 bool PerformanceNavigationTiming::getAllowRedirectDetails() const { |
89 ExecutionContext* context = m_frame->document(); | 93 ExecutionContext* context = frame() ? frame()->document() : nullptr; |
90 SecurityOrigin* securityOrigin = nullptr; | 94 SecurityOrigin* securityOrigin = nullptr; |
91 if (context) | 95 if (context) |
92 securityOrigin = context->getSecurityOrigin(); | 96 securityOrigin = context->getSecurityOrigin(); |
93 if (!securityOrigin) | 97 if (!securityOrigin) |
94 return false; | 98 return false; |
95 // TODO(sunjian): Think about how to make this flag deterministic. | 99 // TODO(sunjian): Think about how to make this flag deterministic. |
96 // crbug/693183. | 100 // crbug/693183. |
97 return PerformanceBase::allowsTimingRedirect( | 101 return PerformanceBase::allowsTimingRedirect( |
98 m_resourceTimingInfo->redirectChain(), | 102 m_resourceTimingInfo->redirectChain(), |
99 m_resourceTimingInfo->finalResponse(), *securityOrigin, context); | 103 m_resourceTimingInfo->finalResponse(), *securityOrigin, context); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 DOMHighResTimeStamp PerformanceNavigationTiming::loadEventEnd() const { | 170 DOMHighResTimeStamp PerformanceNavigationTiming::loadEventEnd() const { |
167 DocumentLoadTiming* timing = documentLoadTiming(); | 171 DocumentLoadTiming* timing = documentLoadTiming(); |
168 if (!timing) | 172 if (!timing) |
169 return 0.0; | 173 return 0.0; |
170 return PerformanceBase::monotonicTimeToDOMHighResTimeStamp( | 174 return PerformanceBase::monotonicTimeToDOMHighResTimeStamp( |
171 m_timeOrigin, timing->loadEventEnd()); | 175 m_timeOrigin, timing->loadEventEnd()); |
172 } | 176 } |
173 | 177 |
174 AtomicString PerformanceNavigationTiming::type() const { | 178 AtomicString PerformanceNavigationTiming::type() const { |
175 DocumentLoader* loader = documentLoader(); | 179 DocumentLoader* loader = documentLoader(); |
176 DCHECK(loader); | 180 if (!loader) |
177 Document* document = m_frame->document(); | 181 return "navigate"; |
| 182 Document* document = frame() ? frame()->document(): nullptr; |
178 switch (PerformanceBase::getNavigationType(loader->getNavigationType(), | 183 switch (PerformanceBase::getNavigationType(loader->getNavigationType(), |
179 document)) { | 184 document)) { |
180 case NavigationType::Prerender: | 185 case NavigationType::Prerender: |
181 return "prerender"; | 186 return "prerender"; |
182 case NavigationType::Reload: | 187 case NavigationType::Reload: |
183 return "reload"; | 188 return "reload"; |
184 case NavigationType::BackForward: | 189 case NavigationType::BackForward: |
185 return "back_forward"; | 190 return "back_forward"; |
186 case NavigationType::Navigate: | 191 case NavigationType::Navigate: |
187 return "navigate"; | 192 return "navigate"; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 builder.addNumber("domInteractive", domInteractive()); | 250 builder.addNumber("domInteractive", domInteractive()); |
246 builder.addNumber("domContentLoadedEventStart", domContentLoadedEventStart()); | 251 builder.addNumber("domContentLoadedEventStart", domContentLoadedEventStart()); |
247 builder.addNumber("domContentLoadedEventEnd", domContentLoadedEventEnd()); | 252 builder.addNumber("domContentLoadedEventEnd", domContentLoadedEventEnd()); |
248 builder.addNumber("domComplete", domComplete()); | 253 builder.addNumber("domComplete", domComplete()); |
249 builder.addNumber("loadEventStart", loadEventStart()); | 254 builder.addNumber("loadEventStart", loadEventStart()); |
250 builder.addNumber("loadEventEnd", loadEventEnd()); | 255 builder.addNumber("loadEventEnd", loadEventEnd()); |
251 builder.addString("type", type()); | 256 builder.addString("type", type()); |
252 builder.addNumber("redirectCount", redirectCount()); | 257 builder.addNumber("redirectCount", redirectCount()); |
253 } | 258 } |
254 } | 259 } |
OLD | NEW |