| 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 30 matching lines...) Expand all Loading... |
| 41 #include "core/html/HTMLFrameOwnerElement.h" | 41 #include "core/html/HTMLFrameOwnerElement.h" |
| 42 #include "core/loader/DocumentLoader.h" | 42 #include "core/loader/DocumentLoader.h" |
| 43 #include "core/origin_trials/OriginTrials.h" | 43 #include "core/origin_trials/OriginTrials.h" |
| 44 #include "core/timing/PerformanceTiming.h" | 44 #include "core/timing/PerformanceTiming.h" |
| 45 | 45 |
| 46 static const double kLongTaskThreshold = 0.05; | 46 static const double kLongTaskThreshold = 0.05; |
| 47 | 47 |
| 48 static const char kUnknownAttribution[] = "unknown"; | 48 static const char kUnknownAttribution[] = "unknown"; |
| 49 static const char kAmbiguousAttribution[] = "multiple-contexts"; | 49 static const char kAmbiguousAttribution[] = "multiple-contexts"; |
| 50 static const char kSameOriginAttribution[] = "same-origin"; | 50 static const char kSameOriginAttribution[] = "same-origin"; |
| 51 static const char kAncestorAttribution[] = "cross-origin-ancestor"; | 51 static const char kSameOriginSelfAttribution[] = "same-origin-self"; |
| 52 static const char kDescendantAttribution[] = "cross-origin-descendant"; | 52 static const char kSameOriginAncestorAttribution[] = "same-origin-ancestor"; |
| 53 static const char kSameOriginDescendantAttribution[] = "same-origin-descendant"; |
| 54 static const char kCrossOriginAncestorAttribution[] = "cross-origin-ancestor"; |
| 55 static const char kCrossOriginDescendantAttribution[] = |
| 56 "cross-origin-descendant"; |
| 53 static const char kCrossOriginAttribution[] = "cross-origin-unreachable"; | 57 static const char kCrossOriginAttribution[] = "cross-origin-unreachable"; |
| 54 | 58 |
| 55 namespace blink { | 59 namespace blink { |
| 56 | 60 |
| 57 namespace { | 61 namespace { |
| 58 | 62 |
| 59 String getFrameAttribute(HTMLFrameOwnerElement* frameOwner, | 63 String getFrameAttribute(HTMLFrameOwnerElement* frameOwner, |
| 60 const QualifiedName& attrName, | 64 const QualifiedName& attrName, |
| 61 bool truncate) { | 65 bool truncate) { |
| 62 String attrValue; | 66 String attrValue; |
| 63 if (frameOwner->hasAttribute(attrName)) { | 67 if (frameOwner->hasAttribute(attrName)) { |
| 64 attrValue = frameOwner->getAttribute(attrName); | 68 attrValue = frameOwner->getAttribute(attrName); |
| 65 if (truncate && attrValue.length() > 100) | 69 if (truncate && attrValue.length() > 100) |
| 66 attrValue = attrValue.substring(0, 100); // Truncate to 100 chars | 70 attrValue = attrValue.substring(0, 100); // Truncate to 100 chars |
| 67 } | 71 } |
| 68 return attrValue; | 72 return attrValue; |
| 69 } | 73 } |
| 70 | 74 |
| 75 const char* sameOriginAttribution(Frame* observerFrame, Frame* culpritFrame) { |
| 76 if (observerFrame == culpritFrame) |
| 77 return kSameOriginSelfAttribution; |
| 78 if (observerFrame->tree().isDescendantOf(culpritFrame)) |
| 79 return kSameOriginAncestorAttribution; |
| 80 if (culpritFrame->tree().isDescendantOf(observerFrame)) |
| 81 return kSameOriginDescendantAttribution; |
| 82 return kSameOriginAttribution; |
| 83 } |
| 84 |
| 71 } // namespace | 85 } // namespace |
| 72 | 86 |
| 73 static double toTimeOrigin(LocalFrame* frame) { | 87 static double toTimeOrigin(LocalFrame* frame) { |
| 74 if (!frame) | 88 if (!frame) |
| 75 return 0.0; | 89 return 0.0; |
| 76 | 90 |
| 77 Document* document = frame->document(); | 91 Document* document = frame->document(); |
| 78 if (!document) | 92 if (!document) |
| 79 return 0.0; | 93 return 0.0; |
| 80 | 94 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 !toDocument(taskContext)->frame()) { | 192 !toDocument(taskContext)->frame()) { |
| 179 // Unable to attribute as no script was involved. | 193 // Unable to attribute as no script was involved. |
| 180 return std::make_pair(kUnknownAttribution, nullptr); | 194 return std::make_pair(kUnknownAttribution, nullptr); |
| 181 } | 195 } |
| 182 | 196 |
| 183 // Exactly one culprit location, attribute based on origin boundary. | 197 // Exactly one culprit location, attribute based on origin boundary. |
| 184 Frame* culpritFrame = toDocument(taskContext)->frame(); | 198 Frame* culpritFrame = toDocument(taskContext)->frame(); |
| 185 DCHECK(culpritFrame); | 199 DCHECK(culpritFrame); |
| 186 if (canAccessOrigin(observerFrame, culpritFrame)) { | 200 if (canAccessOrigin(observerFrame, culpritFrame)) { |
| 187 // From accessible frames or same origin, return culprit location URL. | 201 // From accessible frames or same origin, return culprit location URL. |
| 188 return std::make_pair(kSameOriginAttribution, culpritFrame->domWindow()); | 202 return std::make_pair(sameOriginAttribution(observerFrame, culpritFrame), |
| 203 culpritFrame->domWindow()); |
| 189 } | 204 } |
| 190 // For cross-origin, if the culprit is the descendant or ancestor of | 205 // For cross-origin, if the culprit is the descendant or ancestor of |
| 191 // observer then indicate the *closest* cross-origin frame between | 206 // observer then indicate the *closest* cross-origin frame between |
| 192 // the observer and the culprit, in the corresponding direction. | 207 // the observer and the culprit, in the corresponding direction. |
| 193 if (culpritFrame->tree().isDescendantOf(observerFrame)) { | 208 if (culpritFrame->tree().isDescendantOf(observerFrame)) { |
| 194 // If the culprit is a descendant of the observer, then walk up the tree | 209 // If the culprit is a descendant of the observer, then walk up the tree |
| 195 // from culprit to observer, and report the *last* cross-origin (from | 210 // from culprit to observer, and report the *last* cross-origin (from |
| 196 // observer) frame. If no intermediate cross-origin frame is found, then | 211 // observer) frame. If no intermediate cross-origin frame is found, then |
| 197 // report the culprit directly. | 212 // report the culprit directly. |
| 198 Frame* lastCrossOriginFrame = culpritFrame; | 213 Frame* lastCrossOriginFrame = culpritFrame; |
| 199 for (Frame* frame = culpritFrame; frame != observerFrame; | 214 for (Frame* frame = culpritFrame; frame != observerFrame; |
| 200 frame = frame->tree().parent()) { | 215 frame = frame->tree().parent()) { |
| 201 if (!canAccessOrigin(observerFrame, frame)) { | 216 if (!canAccessOrigin(observerFrame, frame)) { |
| 202 lastCrossOriginFrame = frame; | 217 lastCrossOriginFrame = frame; |
| 203 } | 218 } |
| 204 } | 219 } |
| 205 return std::make_pair(kDescendantAttribution, | 220 return std::make_pair(kCrossOriginDescendantAttribution, |
| 206 lastCrossOriginFrame->domWindow()); | 221 lastCrossOriginFrame->domWindow()); |
| 207 } | 222 } |
| 208 if (observerFrame->tree().isDescendantOf(culpritFrame)) { | 223 if (observerFrame->tree().isDescendantOf(culpritFrame)) { |
| 209 return std::make_pair(kAncestorAttribution, nullptr); | 224 return std::make_pair(kCrossOriginAncestorAttribution, nullptr); |
| 210 } | 225 } |
| 211 return std::make_pair(kCrossOriginAttribution, nullptr); | 226 return std::make_pair(kCrossOriginAttribution, nullptr); |
| 212 } | 227 } |
| 213 | 228 |
| 214 void Performance::reportLongTask(double startTime, | 229 void Performance::reportLongTask(double startTime, |
| 215 double endTime, | 230 double endTime, |
| 216 ExecutionContext* taskContext, | 231 ExecutionContext* taskContext, |
| 217 bool hasMultipleContexts) { | 232 bool hasMultipleContexts) { |
| 218 std::pair<String, DOMWindow*> attribution = Performance::sanitizedAttribution( | 233 std::pair<String, DOMWindow*> attribution = Performance::sanitizedAttribution( |
| 219 taskContext, hasMultipleContexts, frame()); | 234 taskContext, hasMultipleContexts, frame()); |
| 220 DOMWindow* culpritDomWindow = attribution.second; | 235 DOMWindow* culpritDomWindow = attribution.second; |
| 221 if (!culpritDomWindow || !culpritDomWindow->document() || | 236 if (!culpritDomWindow || !culpritDomWindow->document() || |
| 222 !culpritDomWindow->document()->localOwner()) { | 237 !culpritDomWindow->document()->localOwner()) { |
| 223 addLongTaskTiming(startTime, endTime, attribution.first, "", "", ""); | 238 addLongTaskTiming(startTime, endTime, attribution.first, "", "", ""); |
| 224 } else { | 239 } else { |
| 225 HTMLFrameOwnerElement* frameOwner = | 240 HTMLFrameOwnerElement* frameOwner = |
| 226 culpritDomWindow->document()->localOwner(); | 241 culpritDomWindow->document()->localOwner(); |
| 227 addLongTaskTiming(startTime, endTime, attribution.first, | 242 addLongTaskTiming(startTime, endTime, attribution.first, |
| 228 getFrameAttribute(frameOwner, HTMLNames::srcAttr, false), | 243 getFrameAttribute(frameOwner, HTMLNames::srcAttr, false), |
| 229 getFrameAttribute(frameOwner, HTMLNames::idAttr, false), | 244 getFrameAttribute(frameOwner, HTMLNames::idAttr, false), |
| 230 getFrameAttribute(frameOwner, HTMLNames::nameAttr, true)); | 245 getFrameAttribute(frameOwner, HTMLNames::nameAttr, true)); |
| 231 } | 246 } |
| 232 } | 247 } |
| 233 | 248 |
| 234 } // namespace blink | 249 } // namespace blink |
| OLD | NEW |