Chromium Code Reviews| Index: third_party/WebKit/Source/core/timing/Performance.cpp |
| diff --git a/third_party/WebKit/Source/core/timing/Performance.cpp b/third_party/WebKit/Source/core/timing/Performance.cpp |
| index e8402d527b83e817adafcd38c2ec1c91a1b20a52..edca848e8888fdeea689dee819eb9ff13d37b78b 100644 |
| --- a/third_party/WebKit/Source/core/timing/Performance.cpp |
| +++ b/third_party/WebKit/Source/core/timing/Performance.cpp |
| @@ -34,12 +34,17 @@ |
| #include "bindings/core/v8/ScriptValue.h" |
| #include "bindings/core/v8/V8ObjectBuilder.h" |
| #include "core/dom/Document.h" |
| +#include "core/dom/QualifiedName.h" |
| +#include "core/frame/DOMWindow.h" |
| #include "core/frame/LocalFrame.h" |
| #include "core/frame/UseCounter.h" |
| +#include "core/html/HTMLFrameOwnerElement.h" |
| #include "core/loader/DocumentLoader.h" |
| #include "core/origin_trials/OriginTrials.h" |
| #include "core/timing/PerformanceTiming.h" |
| +#include <tuple> |
| + |
| static const double kLongTaskThreshold = 0.05; |
| static const char kUnknownAttribution[] = "unknown"; |
| @@ -51,6 +56,22 @@ static const char kCrossOriginAttribution[] = "cross-origin-unreachable"; |
| namespace blink { |
| +namespace { |
| + |
| +String getFrameAttribute(HTMLFrameOwnerElement* frameOwner, |
| + const QualifiedName& attrName, |
| + bool truncate) { |
| + String attrValue; |
| + if (frameOwner->hasAttribute(attrName)) { |
| + attrValue = frameOwner->getAttribute(attrName); |
| + if (truncate && attrValue.length() > 100) |
| + attrValue = attrValue.substring(0, 100); // Truncate to 100 chars |
| + } |
| + return attrValue; |
| +} |
| + |
| +} // namespace |
| + |
| static double toTimeOrigin(LocalFrame* frame) { |
| if (!frame) |
| return 0.0; |
| @@ -189,13 +210,31 @@ std::pair<String, DOMWindow*> Performance::sanitizedAttribution( |
| return std::make_pair(kCrossOriginAttribution, nullptr); |
| } |
| +std::tuple<String, String, String> Performance::culpritFrameAttributes( |
|
skobes
2016/11/22 00:21:25
It seems unnecessary to wrap these in a std::tuple
panicker
2016/11/22 00:39:47
Agreed. Done.
|
| + HTMLFrameOwnerElement* frameOwner) { |
| + return std::make_tuple( |
| + getFrameAttribute(frameOwner, HTMLNames::srcAttr, false), |
| + getFrameAttribute(frameOwner, HTMLNames::idAttr, true), |
| + getFrameAttribute(frameOwner, HTMLNames::nameAttr, true)); |
| +} |
| + |
| void Performance::reportLongTask( |
| double startTime, |
| double endTime, |
| const HeapHashSet<Member<Frame>>& contextFrames) { |
| std::pair<String, DOMWindow*> attribution = |
| Performance::sanitizedAttribution(contextFrames, frame()); |
| - addLongTaskTiming(startTime, endTime, attribution.first, attribution.second); |
| + DOMWindow* culpritDomWindow = attribution.second; |
| + if (!culpritDomWindow || !culpritDomWindow->document() || |
| + !culpritDomWindow->document()->localOwner()) { |
| + addLongTaskTiming(startTime, endTime, attribution.first, "", "", ""); |
| + } else { |
| + std::tuple<String, String, String> frameAttribution = |
| + culpritFrameAttributes(culpritDomWindow->document()->localOwner()); |
| + addLongTaskTiming( |
| + startTime, endTime, attribution.first, std::get<0>(frameAttribution), |
| + std::get<1>(frameAttribution), std::get<2>(frameAttribution)); |
| + } |
| } |
| } // namespace blink |